Fork me on GitHub
#clojure-spec
<
2019-07-01
>
seancorfield01:07:42

Updated our code at work to use 0.10.0-RC1 and to switch away from the deprecated generators -- and we were using pos-int on the assumption that it generated strictly positive numbers (although zero doesn't break our tests).

gfredericks10:07:20

that makes me glad I deprecated it ๐Ÿ™‚ did you switch to (gen/fmap inc gen/nat), or something else?

seancorfield12:07:04

For now we just switched to gen/nat to preserve the behavior but we will revisit that test and see what might happen if it ever generates zero. At least it is clear now!

gfredericks12:07:58

I can assure you it generates zero quite often ๐Ÿ™‚

seancorfield13:07:06

That test should probably fail with zero (but it doesn't) ๐Ÿ˜•

gfredericks13:07:07

computers are crazypants

seancorfield16:07:17

@gfredericks What's the thinking behind deprecating those generators?

gfredericks19:07:27

pos-int and neg-int are highly misleading w.r.t. 0, and all five of them are misleading w.r.t. size; I think generators by default should generate a healthy range of things, and if you want to restrict yourself to small numbers you should have to be explicit

gfredericks19:07:06

so it's basically entirely a naming issue

gfredericks19:07:01

spose I could've also deprecate-renamed gen/ratio to gen/small-ratio

seancorfield20:07:22

Are you actually planning to remove them at some point (a breaking change) or just "strongly discourage" their usage?

gfredericks20:07:40

there's already another deprecated generator of that sort

seancorfield20:07:04

I found 15 occurrences of "deprecated" in that file ๐Ÿ™‚

seancorfield20:07:20

(seven functions)

gfredericks20:07:28

entirely for naming, apparently:

(def ^{:deprecated "0.6.0"}
  char-alpha-numeric
  "Deprecated - use char-alphanumeric instead.

  Generates alphanumeric characters."
  char-alphanumeric)

seancorfield20:07:25

Naming is hard. I struggled with deprecation/breakage in clojure.java.jdbc and ended up breaking the API twice to get it consistent and idiomatic. With hindsight I would have done it differently.

gfredericks20:07:51

yeah I've tried to figure out how to overhaul things so many times, and largely haven't

cjsauer18:07:36

Does spec have a simple way to express xor with map keys? Meaning map m can have key :a or key :b, but not both.

Alex Miller (Clojure team)18:07:26

Not built in, but you can s/and any predicate you like

๐Ÿ‘ 4
akiel18:07:24

Has someone a solution for using st/instrument with :stub were the function is called more than once and I like to have return values depending on the inputs? With Java mock frameworks such things are possible. With spec I donโ€™t have an idea how to do it. Thanks!

Alex Miller (Clojure team)18:07:24

You canโ€™t with stub, but you could make a stateful :replace fn

akiel18:07:50

@alexmiller Work perfect. Thanks! Not as elegant like mock libs but one could build a helper function which maps inputs to outputs.

seancorfield01:07:42

Updated our code at work to use 0.10.0-RC1 and to switch away from the deprecated generators -- and we were using pos-int on the assumption that it generated strictly positive numbers (although zero doesn't break our tests).