This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-17
Channels
- # announcements (6)
- # babashka-sci-dev (6)
- # beginners (99)
- # biff (3)
- # cider (4)
- # clerk (44)
- # clj-kondo (2)
- # clojure (65)
- # clojure-europe (57)
- # clojure-germany (5)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-spec (19)
- # clojure-uk (3)
- # clojurescript (8)
- # conjure (3)
- # cursive (21)
- # datahike (19)
- # datomic (1)
- # events (7)
- # fulcro (14)
- # graalvm (3)
- # gratitude (1)
- # guix (5)
- # honeysql (1)
- # humbleui (19)
- # hyperfiddle (39)
- # lsp (4)
- # malli (7)
- # music (1)
- # off-topic (33)
- # pathom (65)
- # re-frame (9)
- # reagent (3)
- # reitit (6)
- # releases (1)
- # sql (15)
- # tools-build (7)
- # vim (5)
- # xtdb (16)
Hi, Is there a project that shows best practices for spec? Not a sample but some lib that is actually used. Thanks
Spec can be used in a lot of different ways so I wouldn't expect any single project to be a good exemplar of it... Is there some specific aspect of Spec that you're seeking guidance on?
Just basics, how do I spec parameters on a function best. What are typical project setups, i.e. are the specs in the code or the tests. Do you instrument specs in prodcution or not (or when)? Just all the things that make the idea workable.
I think any well “spec-d” code base woudl be a good starting point. I just don’t know how to google for one.
Those are all good questions. http://grep.app is pretty good for finding code in the wild, https://grep.app/search?q=s/def.
Thank you,. I will give that a try.
https://corfield.org/blog/2019/09/13/using-spec/ talks about the various ways we use Spec at work. Happy to answer any follow-up Qs.
Sean, I did read your blog. Great content. For me it isn’t obvious how to get from the concept to the practical implementation.
I suspect there's a lot more use of Spec in large application codebases and those are nearly all closed source.
I would love to see the Nubank code base 🙂
I work with a lot of FSI customer and I am trying to figure out if we can simplify some of those problems.
> Do you instrument specs in prodcution or not (or when)? I personally wouldn't use instrumentation outside of development. If you use spec for API/request validation, or generally stuff that comes from the outside of your program, then you want to be somewhat rigorous with it and nail it down to sufficient detail. Otherwise I would say just use it when it helps, incrementally. For example it can be useful as a thinking tool, to design the shape of your data. Or you can use conform to parse things into a richer structure. But it's really just that, a tool. I played around with it a lot and looked at how people use it in OSS projects. It's very nice and composable, and you can do a lot with it. I think playing around with it is a good way to get familiar with what you can do. Then forget about it, just write code and it will introduce itself naturally.
Here's are more involved specs (tools.deps): https://github.com/clojure/tools.deps/blob/master/src/main/clojure/clojure/tools/deps/specs.clj Specs can also be small and informal, basically just a set of names https://github.com/cognitect-labs/anomalies/blob/master/src/cognitect/anomalies.cljc
Another example from a library: https://github.com/seancorfield/next-jdbc/blob/develop/src/next/jdbc/specs.clj -- all about instrumenting library functions during development
Fantastic just what I needed. Thank you so much.
> Generative scenario testing
This is a very interesting section. I've been thinking about something similar in the back of my head for a while. I named them workflows, but I like "scenario" very much as a term here!
> Deriving code from specs
I've been struggling with something similar for quite a while and was never quite happy with my results. Have you been using form
and conform
to parse the specs themselves?
I'm not in front of my work codebase -- I'm taking every Friday off this month -- but I'm pretty sure we use form
and walk the result to find the s/keys
definition and "parse" that to derive everything we need. If you remind me on Monday, I can provide more detail.
https://practical.li/clojure/clojure-spec/ covers how I use clojure.spec along with practical examples and coding videos I've also recently been using spec with Reitit to validate API requests and responses (which I will be writing up this month)