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-12-21T18:08:36.002100Z

(do
  (defn f [x] x)
  (s/fdef f :ret int?)
  (stest/instrument)
  (f "hello"))
i would expect this to throw, but i don't see that happening. what am i missing?

mpenet 2020-12-22T14:55:24.007900Z

there are many of these libs, guardrails, orchestra, ghostwheel

mpenet 2020-12-22T14:55:41.008100Z

some use instrument/check, some avoid it (intentionally)

borkdude 2020-12-22T14:56:30.008300Z

I saw in the #announcements channel that guardrails now has an async instrumentation thing, so it doesn't slow down your functions but you will eventually know something is wrong - at least that's what I got from it

mpenet 2020-12-22T14:58:53.008500Z

yeah, it's optional. I think the approach with guardrails is by default just to log the failures

mpenet 2020-12-22T14:59:00.008700Z

so that's ok to do it that way

mpenet 2020-12-22T14:59:44.008900Z

I *reall*y wonder what spec2 will do in that regard, since apparently it's one area where there's some heavy hammocking going on. [edit] By that I don't mean Rich is heavy!

borkdude 2020-12-22T14:59:54.009100Z

Interesting way to solve the slowness that instrumentation brings.

mpenet 2020-12-22T15:07:00.009500Z

but yes, guardrails is the most interesting of the bunch so far imho. One thing is missing is editor support (indentation annotations), it's a bit ugly out of the box

borkdude 2020-12-22T15:11:16.010Z

you mean like flycheck integration? that's pretty easy if you have file:line:col: ERROR message kind of output

mpenet 2020-12-22T15:11:43.010200Z

no, indentation, if you use something like aggressive-ident on emacs you'll get some ugly defn's with guardrails

mpenet 2020-12-22T15:11:53.010400Z

(same with cljfmt)

borkdude 2020-12-22T15:12:04.010600Z

isn't that a general clojure tooling problem then?

mpenet 2020-12-22T15:12:09.010800Z

it's easy to solve, at conf level or even lib level

mpenet 2020-12-22T15:12:33.011Z

you can add annotation to the macros to give hints to editors :style/ident

mpenet 2020-12-22T15:12:52.011200Z

it's not standard, but I think both emacs/cursive support it at least

borkdude 2020-12-22T15:13:02.011400Z

right. oh, this tool forces you to use a different defn macro? hmm

mpenet 2020-12-22T15:13:03.011600Z

maybe even cljfmt

mpenet 2020-12-22T15:13:07.011800Z

yeah

mpenet 2020-12-22T15:13:17.012Z

well no, you can also use the annotation version

mpenet 2020-12-22T15:13:28.012200Z

but you also have these def defn macros

mpenet 2020-12-22T15:14:15.012600Z

we use it quite a lot, and like it. Sure there are rough edges but nothing too bad

mpenet 2020-12-22T15:14:34.012800Z

(spec1 I mean)

valerauko 2020-12-21T18:14:02.002200Z

are you doing this in the repl? I've had surprising behavior wrapping defn and similar in do/let. Try executing line-by-line?

seancorfield 2020-12-21T18:14:35.002400Z

instrument is for argument checking, not return value checking.

👌 1
seancorfield 2020-12-21T18:15:13.002600Z

instrument checks that your function is being called correctly by other code. check is what you use to generatively test the behavior of the function itself.

2020-12-21T18:37:04.003Z

@seancorfield, thank you!

2020-12-21T18:37:22.003200Z

i misunderstood instrument

seancorfield 2020-12-21T18:38:47.003400Z

I think almost everyone does when they first start using Spec.

borkdude 2020-12-21T19:32:42.003700Z

There is an unofficial spec tool which will check return values as well, called orchestra

seancorfield 2020-12-21T19:35:53.003900Z

I think that library is a bit misguided since it deliberately blurs the lines that Clojure Spec draws by design. Caveat programmer.

borkdude 2020-12-21T19:36:44.004100Z

Seemed worth mentioning, because a lot of people use it exactly for this reason.

seancorfield 2020-12-21T20:34:29.004400Z

No comment 🙂

borkdude 2020-12-21T20:35:06.004600Z

Hehe, well, I don't use it either ;)