Fork me on GitHub
#clojure-spec
<
2023-03-17
>
Joerg Schmuecker18:03:08

Hi, Is there a project that shows best practices for spec? Not a sample but some lib that is actually used. Thanks

seancorfield19:03:52

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?

Joerg Schmuecker20:03:39

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.

Joerg Schmuecker20:03:33

I think any well “spec-d” code base woudl be a good starting point. I just don’t know how to google for one.

phronmophobic20:03:53

Those are all good questions. http://grep.app is pretty good for finding code in the wild, https://grep.app/search?q=s/def.

Joerg Schmuecker20:03:26

Thank you,. I will give that a try.

seancorfield20:03:26

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.

Joerg Schmuecker20:03:14

Sean, I did read your blog. Great content. For me it isn’t obvious how to get from the concept to the practical implementation.

seancorfield20:03:29

I suspect there's a lot more use of Spec in large application codebases and those are nearly all closed source.

Joerg Schmuecker20:03:40

I would love to see the Nubank code base 🙂

Joerg Schmuecker21:03:31

I work with a lot of FSI customer and I am trying to figure out if we can simplify some of those problems.

dgb2322:03:19

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

seancorfield22:03:37

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

👀 2
Joerg Schmuecker23:03:14

Fantastic just what I needed. Thank you so much.

dgb2323:03:23

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

seancorfield23:03:52

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.

🙏 2
👍 2
dgb2323:03:33

Ah right, its a specific subset of possible specs that make sense in that context

practicalli-johnny14:03:54

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)