Fork me on GitHub
#clojure-spec
<
2019-05-09
>
ben11:05:33

this is probably a really simple question, but what are the practical differences between using :pre and :post vs spec/fdef for function validation? As far as I can tell, fdef gives you a bit more control, but otherwise :pre/`:post` are just there because they’re more “lightweight”/easier to read?

eskemojoe00713:05:46

I'm a noob with this stuff, but I think :pre and :post run at runtime. fdef doesn't run at runtime, only during testing.

ben13:05:30

this rings true with the docs now I read them back, actually

jumar16:05:51

fn specs defined via fdef don't run by default - they run in whatever environment you want if you toggle those via stest/instrument (https://clojure.github.io/spec.alpha/clojure.spec.test.alpha-api.html#clojure.spec.test.alpha/instrument)

jumar16:05:14

And yes, it's not usually recommended for production use, only for testing/development

thumbnail07:05:27

:pre, and :post can be toggled by rebinding *assert* as well though