Fork me on GitHub
#clojure-spec
<
2016-09-08
>
bbloom02:09:53

i just want to say: i’ve been writing javascript with flowtype for the past ~2 weeks. It’s a very nice type system and it’s very well implemented…. and I absolutely hate it. I miss clojure 😞

seancorfield02:09:43

@bbloom No, no, you must be mistaken. Type systems are awesome 🙂

seancorfield02:09:32

I’m finding new things to use clojure.spec for almost every day, I have to say…

bbloom02:09:46

i think i’ve hit more false positives about NPEs from flowtype in two weeks than i’ve had ACTUAL NPEs in a year of Go

seancorfield02:09:25

So it’s telling you "This will likely NPE" but the code wouldn’t?

bbloom03:09:47

basically it says something like “potentially null or undefined” b/c it’s doing a map lookup or something, but i know with 100% confidence by construction that value is in the map

bbloom03:09:06

or similar

bbloom03:09:00

you wind up having to employ strategies all over the place:

bbloom03:09:09

1) making tons of extra structure types for every possible state of things

bbloom03:09:52

and 2) using invariant(whatever, ‘whatever may not be null’) which basically is just a glorified manual throw npe

seancorfield03:09:00

Must admit, when we were using core.typed at work, that was one of the problems we had: nil was contagious and then we kept getting complaints about code not accepting nil (when we knew nil wouldn't flow to that point),

shaun-mahood03:09:45

@seancorfield: Have you run into anything like that with spec yet?

seancorfield05:09:40

@shaun-mahood no, but that’s because spec isn’t "contagious" in the same way that type systems tend to be: spec’ing one piece of code doesn’t ripple out into other pieces of code.

shaun-mahood05:09:25

@seancorfield: That's awesome - I ran into similar issues with schema in a very limited manner and it really bothered me. I know you'll put spec through a lot more than I ever will so I've been using your notes and comments about as sort of my real-world expectations.

seancorfield05:09:28

I'm surprised you hit that with Schema since it's really just runtime assertions.

shaun-mahood06:09:08

Well, it's more likely that I did something stupid or am remembering different problems then - I really didn't put a whole ton of effort into figuring out exactly what was going on and it was quite a while ago. I probably just didn't know what I was doing as well as I though I did :)

jannis13:09:51

Is it a deliberate difference between Clojure and ClojureScript that ClojureScript's clojure.spec.test/check only accepts a literal collection of syms instead of a code-generated value (e.g. (let [syms (filter in-my-namespaces? (st/checkable-syms))] (st/check syms)) will not work as it raises a Unable to resolve symbol: syms error.

jeroenvandijk14:09:59

Question about multi-spec, is it meant/possible to use with something else than a map? I cannot find examples and after a lot of trying it seems the multi-spec implementation doesn’t call the multi-method like one would expect

jeroenvandijk14:09:34

ah ok, i had a clear moment. I was a victim of multimethod + multi-spec reloading. It is possible with the right dispatch function

Alex Miller (Clojure team)15:09:13

retagging is discussed in the docstring - it’s for gen and can be a fn as well

Alex Miller (Clojure team)15:09:18

@jannis prob a question @dnolen would have to answer re check

jannis15:09:21

@alexmiller Ok, I'll check with him

jannis16:09:23

Might as well do it here. @dnolen: ping 😉

jeroenvandijk16:09:44

@tmtwd yep, we use it. Not in something we deployed in production (yet). But I have used it quite a lot now and it works well

jeroenvandijk16:09:19

Is anybody doing things with clojure.spec/unform at the moment? I asked something on the mailinglist about using it for data migrations, but no answer yet

Alex Miller (Clojure team)17:09:27

not many from my impression (given the number of bugs I am aware of but no one has mentioned yet :)

Alex Miller (Clojure team)17:09:48

data migration is one interesting use case for it though

jeroenvandijk17:09:16

thanks, for confirming the use case 🙂 I’ll see if I can make it work

dmarjenburgh18:09:26

Hello. With multi-spec, is there a way to generate values conforming to only a specific dispatch-value? For example, in the :event/event example in http://clojure.org/guides/spec, the generator generates all events. What is the best way to generate events of only a certain type?

bfabry18:09:16

@dmarjenburgh you can get the spec (and hence the generator) for a specific dispatch value by just invoking the multi-method, (event-type {:event/type :event/search})

dmarjenburgh18:09:18

Ah, ofcourse. Thanks! 🙂