Fork me on GitHub
#clojure-spec
<
2018-04-26
>
borkdude09:04:30

Gary talked about an interesting issue recently. What if you instrument all and there are loads of fdefs for core functions. This will create a lot of validation overhead. Anyone experienced this becoming an issue?

Alex Miller (Clojure team)11:04:09

Currently, no core functions are spec’ed (just macros, which are done at compile time not runtime, although admittedly those are often pretty close together in repl dev). Having too much instrumented definitely can create a noticeable effect.

Oliver George09:04:37

There's definitely overhead. By rights it shouldn't matter so much at dev time which is the common use case for instrumenting.

gfredericks12:04:48

it'll matter if specs get added to clojure core fns; I can easily imagine a 10000x slowdown depending on what you're doing

Rose Molina09:04:44

Good morning, I recently started using spec and I wanted to know the reason behind why s/and conforms values and propagates them. I hadn't read the spec guide (https://clojure.org/guides/spec#_spec_ing_functions) in full before I found the first example of this in our code base and I found it hard to read.

Alex Miller (Clojure team)11:04:10

conforming tells you not just whether something validated (like valid? but how it validated - indicating which alternatives are taken and how value components were parsed). Flowing conformed values allows s/and to also flow conform info out to the user from internal components (which is also done in most other conforms)

dominicm13:04:27

Is it possible to "redirect" a failure. For example, if a list of numbers must be sequential, this validation can only be performed on the "whole", but the failure is on a particular index.

Alex Miller (Clojure team)13:04:38

not without implementing your own spec

dominicm14:04:14

@alexmiller is that api private currently?

Alex Miller (Clojure team)14:04:30

it’s public but undocumented and subject to violent change

Alex Miller (Clojure team)14:04:09

as in, I expect it to change, and possibly even be completely replaced.

dominicm14:04:12

I'll wait on that, knowing it isn't impossible is good.

Alex Miller (Clojure team)14:04:23

things like spec-tools are using it extensively

dominicm14:04:27

It was one frustration I'd had, e.g. for password validation data.

dominicm14:04:41

Yeah, I wasn't touching it because I know it will break some day.

ikitommi15:04:51

the Spec protocol will be replaced? Is it possible to comment or discuss on the upcoming changes, from 3rd party library maintainer perspective?

Alex Miller (Clojure team)15:04:10

no, I don’t know yet what they will be

Alex Miller (Clojure team)15:04:29

it may be replaced, it may not be replaced, it may change, I have no idea yet

Alex Miller (Clojure team)15:04:08

this is the alpha part of spec.alpha

Alex Miller (Clojure team)15:04:30

my advice right now would be - don’t use that

Alex Miller (Clojure team)15:04:31

I expect changes to the main user api of spec to be minimal or at least well thought about

ikitommi15:04:49

ok. thanks. there is a alpha disclaimer too on spec-tools, but just checked, it has 13k downloads, so someone is using that already. hopefully there is a way to port the features to new spec apis - or remove stuff that is implemented by the new core directly.

Alex Miller (Clojure team)15:04:27

I have not been shy about telling spec-tools and others what I said above

Alex Miller (Clojure team)15:04:45

spec-tools is almost certain to be broken by future spec changes

Alex Miller (Clojure team)15:04:26

I don’t agree with most of what that library is doing