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
tikotus 2020-07-15T12:27:40.484300Z

Once in a while I'm toying with Clojure, currently I'm trying to learn how to benefit from specs. I just re-watched Hickey's "Maybe Not" talk to support some thoughts running through my head. I ended up wondering about a thing in the proposed schema solution: In the selection we give ::user [::first ::last] etc. Now what's the point of ::user? Why not just {::first ::last}? Just for communication? I'm not sure of the value it adds to communication. One thought I had was that it's there to tell us that we might be using other stuff from the ::user too, like ::addr, we just don't require it. But isn't this then just a briefer, less informative way of saying {:req [::first ::last] :opt [::addr]}? Now we're just one step away from the old spec :keys. Where did ::user go, what was the value of having a schema? Anyways, are there any news on the next take on spec that I'm missing? Couldn't find anything...

☝️ 1
jaihindhreddy 2020-07-16T12:16:52.492Z

Let's say we're dealing with a scenario where we're dealing with a seller and a buyer, and we need the address of both, then ::seller and ::buyer would be useful. With just ::user, it's not very useful, but if we don't have the ::user in there, that means it's assumed that the ::address is that of the user implicitly, making it context-sensitive. With ::user, we're making it clear that it is user information.

alexmiller 2020-07-15T13:07:56.484900Z

work has been ongoing on the next release at https://github.com/clojure/spec-alpha2

alexmiller 2020-07-15T13:08:36.485400Z

https://github.com/clojure/spec-alpha2/wiki/Schema-and-select is current state

alexmiller 2020-07-15T13:08:57.485700Z

and other differences at https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha

jaihindhreddy 2020-07-15T18:44:03.486200Z

with schema you can describe trees and not just one-level. For example, we can say, address is optional, but when you do give me an address, I need the zip code and the street. Before schema and select, this kind of a thing would result in an ad-hoc spec to be written, and we end up with a parochiality problem.

mikeb 2020-07-15T21:00:29.488200Z

Cool. What's best way to begin trying out spec2, or is that discouraged until it's further along?

seancorfield 2020-07-15T21:05:50.490300Z

@mikeb I'd say it is discouraged at this point. We were tracking it closely at work for several months last year but it's still very fluid and very buggy and there's clearly still some "hammock time" needed. After talking to Alex in September/October about it, we decided to wait until he says it is "baked" before we try it again.

alexmiller 2020-07-15T21:06:22.491100Z

instructions are in the readme if you want to try it as a git dep

seancorfield 2020-07-15T21:06:48.491700Z

I think it's going to be a big improvement over Spec 1, based on our foray into it last year, but be prepared for it to change/break quite a bit as it continues to evolve 🙂

tikotus 2020-07-15T22:03:17.491800Z

I still have two questions: 1. What's the use of ::user at the root in this case? 2. Why is schema needed for a nested select? I don't need a schema for ::address to say that if ::address exists in the map, I require it to contain ::zip and ::street.