News for hackers. Stuff that matters.
Re:Clojure 1.11 planning by dancek on Tuesday October 08, 2019 @06:14AM (#21190538)
Spec is great for validation. For example, we have a HTTP API built using https://github.com/metosin/reitit where we have specs for each endpoint. We have a coercion middleware that checks each request (and optionally response) conforms to a spec (and coerces things like integer ids from path to the correct type). And there's a swagger handler that automatically generates a full documentation of the API just from the route tree and specs, including samples of input and output for all routes.

Similarly you can do HTML form validation, etc.

We even use honeysql with nice helper functions that ensure that data-changing SQL queries are of the expected form. Say, you want to update just one row, you have a helper function that checks the honeysql data has a where clause with a unique column and only then runs the query. Someone should maybe blog about that sometime.

What I've found, though, is that trying to use spec like type checking is usually not a great idea. I expect better from static analysis / compile-time checking, with clj-kondo being the most promising tool atm.

Re:Clojure 1.11 planning by Scarbutt on Tuesday October 08, 2019 @10:44AM (#21192855)
I remember spec being pitch for something you only use at dev time and turn off in production because it makes your runtime very very slow, what has change? Seems users are using it for everything now.
Re:Clojure 1.11 planning by seancorfield on Tuesday October 08, 2019 @04:39PM (#21196978)
Spec has numerous uses. We use it heavily in production for data validation/conformance: https://corfield.org/blog/2019/09/13/using-spec/
Re:Clojure 1.11 planning by fulafel on Tuesday October 08, 2019 @12:47PM (#21194209)
I bet you are thinking of https://clojure.org/guides/spec#_instrumentation_and_testing - it was always just one use of spec among many.
Re:Clojure 1.11 planning by dancek on Tuesday October 08, 2019 @12:02PM (#21193728)
We don't have instrumentation in production, ie. we spec much more at dev time. But for things you'd validate anyway spec is a good match and probably about as performant as hand-written validation.

The only strange use of spec I mentioned is validating db queries. For us updates and deletes are rare enough that perf doesn't matter.

Re:Clojure 1.11 planning by nickik on Tuesday October 08, 2019 @11:41AM (#21193468)
No. It was always designed to be configurable so you can keep on the API endpoints, but deactivate them internally.
Re:Clojure 1.11 planning by dkersten on Tuesday October 08, 2019 @12:23PM (#21193939)
I have a somewhat off-topic question I've been wondering about... How do you pronounce "reitit"? I've been considering giving a talk on it at my local clojure group, so I should probably learn how to actually say the word!
Re:Clojure 1.11 planning by wry_discontent on Tuesday October 08, 2019 @01:56PM (#21195046)
In my brain I usually say re-it-it, but sometimes I think "rye-tit" which makes me laugh and definitely seems wrong.
Re:Clojure 1.11 planning by motor_toni on Wednesday October 09, 2019 @12:15AM (#21199969)
It's more like "ray-tit". A colleague at Metosin came up with a good alternative: "rate it!" Used in sentence like "I reitit 5 out of 5!"
Re:Clojure 1.11 planning by dancek on Tuesday October 08, 2019 @04:51PM (#21197107)
Raitit (rye-tit) is a Finnish word too: the plural of "a lone village road splitting the village in half".

Would make a nice library name. Wonder if Metosin takes requests...

Re:Clojure 1.11 planning by arcatan on Tuesday October 08, 2019 @03:24PM (#21196102)
It's a Finnish word. Google Translate's text-to-speech is pretty decent - click the speaker icon on the left: https://translate.google.com/#view=home&op=translate&sl=fi&t...
Re:Clojure 1.11 planning by dkersten on Tuesday October 08, 2019 @04:42PM (#21197008)
Thank you!