Fork me on GitHub
#clojure-spec
<
2020-09-03
>
kennytilton01:09:25

Is clojure.spec a timid retreat from dynamism? In part bowing before the sacred cow of testing? "tests are essential to quality" --https://clojure.org/about/spec It seems like Clojure ventured bravely forth from the suffocating safety of Java's strong static typing, caught one gust of untyped wind, and scurried back to the shelter of Java's skirts. Or was this just a pragmatic choice to make Clojure more palatable in tall buildings?

kennytilton02:09:22

Not trolling, just trying to decide whether to buy into the burden of spec.

seancorfield02:09:50

You certainly sound like you're trolling @hiskennyness but I know enough of your posts to know that's just kind of your "teasing" style 🙂

seancorfield02:09:46

We use Spec very heavily at work, in production code, to do data validation. It is not any sort of type system so, no, it is not any sort of "scurrying back to Java's skirts" 🙂

seancorfield02:09:41

Have a read of https://corfield.org/blog/2019/09/13/using-spec/ and see the many ways we're using Spec at work -- none of which are in any way as a substitute for types.

seancorfield02:09:06

We do find Spec to be very helpful in testing (and to some extent in development). We use specs to generate test data, to help support property-based testing, to valid test results...

kennytilton02:09:54

Thx! I'll check it out. But reading that intro I kept hearing "OK, we should have objects with defined properties; maps are too loosey-goosey". Lemme see what HisCorfieldNess is up to...

seancorfield02:09:06

(I'm going off to make dinner but I'm certainly happy to discuss Spec in great depth when I get back -- or tomorrow 🙂 )

kennytilton02:09:26

OK, nice, short and sweet. Actually readable! But we likely disagree on testing, so no progress can be made there. As for runtime parameter checking, spec could be a handy way to code up what folks do anyway, but then that could be trivial little DSL I knock off in an hour then evolve easily over time. spec seems to be a handful at times, with people asking for help expressing different things. Sounds like a classic case of a good idea run amok. As for code generation from spec, now you are scaring me. 🙀 We have macros for DSLs, and I write the macro that parses a tree of symbols whose structure can be as user-friendly as I like? Think "CL loop" 🙂. Why parse a spec definition, whose structure I cannot completely control? Even if I can make the latter work, it now feels as if I am in places coding my app in spec so it can be generated, when I already have a fine language to work with (Clojure!). Maybe this is why people get stuck using spec, because they ineluctably get drawn into more and more intense usage trying to program with it. So how widely used is spec?

seancorfield03:09:52

Back from dinner now @hiskennyness... I'd say Spec is pretty widely used. Lots of libraries provide optional Specs in a separate namespace so folks on Clojure 1.8 or earlier can avoid it and anyone on Clojure 1.9 or later can opt in if they wish.

seancorfield03:09:01

As for generating code from Specs, that's about having one "source of truth" and it might as well be the Spec (esp. since mostly it's macros in Spec 1 and they're hard to deal with programmatically -- that will change in Spec 2).

seancorfield03:09:24

And we generate code from Specs we write.

seancorfield03:09:45

Spec has a lot of different uses. Some people do try to use it like a type system (bad idea, IMO, and that's not what it is designed for). Given your skepticism, I can only assume you've not watched any of the (many) talks about Spec over the years? Spec has been available for about four, four and a half years, since 1.9.0-alpha1 in May 2016.

kennytilton12:09:26

I'll google up some vids. Yes, well aware of spec for a while. Just ran into it at work for the first time, so it is time to get to know it. Thx for the feedback!

seancorfield16:09:08

Feel free to ping with any Qs if you want 🙂

borkdude09:09:49

> Lots of libraries provide optional Specs in a separate namespace I think this is good practice also for programs written for > 1.9