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
2020-02-13T04:50:44.187500Z

Would using :replace instead of :stub work in this case?

telekid 2020-02-13T20:45:53.218800Z

Oh, interesting! I’ll look into that, cool idea

2020-02-13T13:37:11.193200Z

Hey folks, Looking for a bit of advice about adding specs to an open source project. We have a "command syntax" where commands are basically vectors. A few examples are provided below but essentially each command's first item is an op-code and subsequent items configure the operation in an op-specific way....

[:do some-side-effect-fn]
[:write! :foo {:id 1 :payload "yolo"} optional-args]
[:watch some-pred optional-args]
Seems like there's a few ways this could be spec'd and I was just wondering if anyone had any thoughts about how I should structure it. There are some additional commands not shown here but not more than 10 overall and I don't anticipate too many more being added in the future.

2020-02-13T13:48:19.195100Z

Ah I've just seen how crux does it. https://github.com/juxt/crux/blob/b7fdb38357adb85627c3be5710d0aff26a796f19/crux-core/src/crux/tx/event.clj I think our commands follow the same sort of pattern as their transactions so can probably just use that. I didn't realize that multi-spec could be used with non-map shaped structures.

2020-02-13T17:41:56.197200Z

If you look in the spec 2 repo currently there is still the keys spec, will that stay? If so, with schemas/select is there a suggested limited set of usecases for keys now?

seancorfield 2020-02-13T17:59:06.198500Z

@colinkahn I have seen a couple of mentions from @alexmiller indicating that keys may not stay in the final Spec 2 version -- but Spec 2 is still very much alpha and in flux. Also the fdef stuff is likely getting a substantial overhaul.

seancorfield 2020-02-13T18:01:27.200700Z

I spent quite a bit of time tracking Spec 2 last year and had a branch of our system at work that passed all tests using Spec 2 instead of Spec 1 -- but still using keys and there were quite a lot of changes just to get to that point (and a number of bugs and workarounds I had to deal with). I gave up in early October and decided that we wouldn't attempt a direct migration from Spec 1 to Spec 2: instead we'll adopt Spec 2 for new code and perhaps incrementally replace our Spec 1 usage over time.

seancorfield 2020-02-13T18:02:30.202Z

One thing that needs to be figured out for a mixed Spec 1/2 codebase is how the spec systems interact, because Clojure itself uses Spec 1 (1.9, 1.10) and so you can't (easily) mix core specs with your own Spec 2 stuff right now.

2020-02-13T18:08:31.205400Z

Thanks for the insight @seancorfield. In your experience do you think your refactor would have been easier if you were already using https://github.com/ComputeSoftware/spec1-select for you spec 1 code? I’m looking to port some of my code over to it. Regarding keys I was curious if the (and) and (or) syntax used within :req/opt(-un) would exist in some form in spec 2.

seancorfield 2020-02-13T18:09:15.206100Z

Our use of Spec dates back to early alphas of Clojure 1.9 so that library is moot for us.

2020-02-13T18:10:09.207300Z

Right, not saying for your specific case but I’m evaluating using it to make our transition to spec 2 eventually smoother

seancorfield 2020-02-13T18:11:07.208400Z

Given how much Spec 2 is in flux, I don't know that such a library would necessarily be a useful starting point. Most of the work for us in attempting to get our Spec 1 codebase running on Spec 2 was around the much stricter delineation of symbolic specs vs spec objects etc.

seancorfield 2020-02-13T18:11:40.209100Z

We had a lot of Spec 1 specs that simply weren't legal in Spec 2 and we had to rewrite them to use defop and various other constructs.

seancorfield 2020-02-13T18:13:06.210100Z

Remember: we stayed with keys when we attempted that migration -- it wasn't about switching to schema/`select`... that was considered "future work".

2020-02-13T18:18:28.213400Z

Good to know, I haven’t dived into the defop stuff in spec 2 yet so didn’t consider that. Besides future compatability I definitely feel the pain points that schema/select are meant to solve, which is why I’m seeing that as a valuable first step.

alexmiller 2020-02-13T19:28:44.214Z

Re and/or - no, probably not

alexmiller 2020-02-13T19:29:06.214800Z

Schemas support unqualified keys in spec 2

seancorfield 2020-02-13T19:47:55.216400Z

Sure, they are a big improvement on Spec 1's keys -- but I would be wary of relying on a 3rd party lib that tries to backport Spec 2 features onto Spec 1 when a) Spec 2 is still changing so much and b) Spec 2 already has stricter rules about "what is a spec" than Spec 1.

seancorfield 2020-02-13T19:48:56.217200Z

I don't consider a lib like that to be a useful "future proofing" option...

seancorfield 2020-02-13T19:50:07.218500Z

(it's an interesting exercise, to be sure, and if folks want some of what Spec 2 offers while staying on Spec 1 for an unspecified future time period then maybe it's of some use -- but I really doubt it will make the "migration" from Spec 1 to Spec 2 any easier)