Fork me on GitHub
#clojure-spec
<
2017-01-17
>
lmergen09:01:49

is anyone else struggling with a sudden ‘spec creep’ in their code ? how would one effectively determine what does and what does not belong in a spec ? e.g. if you’re accepting a file as a parameter, should you spec that this file exists, or should it only spec that it looks like a file ?

lmergen09:01:39

i’m err’ing towards making spec only define what things should look like

joost-diepenmaat09:01:23

@lmergen I would assume that checking for file existence is not very useful since you need to check that actually opening the file succeeded anyway (and do something relevant when that failed). a file existing during precondition does not guarentee that it’s still there when you try to access it

lmergen09:01:54

that makes sense

joost-diepenmaat09:01:43

depending on your code it may make sense to generate files though...

joost-diepenmaat09:01:39

personally I’d try to avoid messing with the filesystem in tests and write as much as possible in terms of sequences or whatever makes sense to your problem

joost-diepenmaat09:01:01

The idea with speccing function arguments as I understand it is to describe whatever input data that is supposed to be handled. In this case, handling non-existing files is sort of necessary given the mutable nature of the file system.

dottedmag09:01:48

@lmergen My rule of thumb: spec predicates should be pure functions.

dottedmag09:01:41

Another one: behaviour of the system should not change if spec checking is disabled (except for the boundaries where spec is explicitly used for parsing/destructuring external data). So all runtime error handling (file not found etc) ought to be in the function itself, and spec should only prevent programming errors.

lmergen09:01:05

what about s/conform ?

joost-diepenmaat09:01:08

if you’re using that explicitly in your function body then you’ve sort of guaranteed the specs can’t be disabled 🙂

joost-diepenmaat09:01:17

same with macros

joost-diepenmaat09:01:18

that’s the parsing case that @dottedmag is talking about I think

dbushenko09:01:50

are there any libs wich already have specs? just wanted to see some good examples of using specs

dottedmag09:01:07

There are some specs for clojure.core already. Mostly macros.

joshjones12:01:58

@lmergen I found myself asking this question recently, and reading the rationale/motivation for spec made things a little clearer. while I like @dottedmag ‘s “only pure functions” rule of thumb, the spec guide itself has a section called “Using spec for validation” that includes several runtime validation examples which are not at the edge of the system at all, but which are deeply integrated. That level of integration makes me a bit nervous, but it’s clear that spec is integrated enough that this is a valid enough use case, at least for some people.

tetriscodes16:01:18

I’m struggling with how much spec right now

tetriscodes16:01:58

I’m thinking of putting it only where developers use the system (http endpoints, components apis,…)

tetriscodes16:01:14

I’ve seen the most benefit in my system from using the generators after specing. Its found more bugs in there than our devs have seen using the functions that are spec’ed.

angusiguess18:01:04

Has anyone had to spec something that might be used by older versions of clojure?

angusiguess18:01:35

What's a good way of providing spec that's only read for 1.9+?

gfredericks19:01:04

seperate namespace for the specs