clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
kennytilton 2020-09-03T01:59:25.047500Z

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?

kennytilton 2020-09-03T02:00:22.048500Z

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

seancorfield 2020-09-03T02:08:50.049200Z

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 🙂

seancorfield 2020-09-03T02:09:46.050300Z

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" 🙂

seancorfield 2020-09-03T02:10:41.051100Z

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.

seancorfield 2020-09-03T02:13:06.053500Z

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...

kennytilton 2020-09-03T02:13:54.054200Z

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...

seancorfield 2020-09-03T02:17:06.054900Z

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

kennytilton 2020-09-03T02:38:26.069600Z

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?

seancorfield 2020-09-03T03:53:52.070800Z

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.

seancorfield 2020-09-03T03:55:01.071900Z

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).

seancorfield 2020-09-03T03:55:24.072200Z

And we generate code from Specs we write.

seancorfield 2020-09-03T03:58:45.074100Z

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.

kennytilton 2020-09-03T12:18:26.075Z

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!

seancorfield 2020-09-03T16:47:08.075200Z

Feel free to ping with any Qs if you want 🙂

borkdude 2020-09-03T09:33:49.074800Z

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