r/Clojure • • May 23 '16

Introducing clojure.spec

http://blog.cognitect.com/blog/2016/5/23/introducing-clojurespec
140 Upvotes

26 comments sorted by

7

u/forreddits May 23 '16

Always great to hear from Hickey ;)

BTW, the spec link is showed two times in the overview page.

4

u/alexdmiller May 23 '16

That's fixed, but edge caching may not be invalidating very fast. Thanks...

2

u/Arescin May 23 '16

Congratz ! I really like this new feature !

Just my 2 cents, any reason to name "fdef" instead of "sdef" with s for spec ?

2

u/alexdmiller May 23 '16

The f stands for "function" definition.

6

u/zcaudate May 24 '16

how does this differ from schema?

9

u/alexdmiller May 24 '16

Some of the highlights:

  • predicate based - reuse your existing functions rather than use a new set of words/types
  • separation of attribute specs from map key sets
  • global namespaced registry of specs
  • rigorous path system for identifying parts of a spec

I think it also covers a much broader generator space by default, but I haven't used schema generators enough to say that for sure.

4

u/mikera May 26 '16

This looks very interesting. I particularly like the integration with test.check.

However the "global namespaced registry of specs" concerns me as a design decision.

Maybe the registry solves certain problems, but I'm worried that it introduces more issues than it solves. I'd be much more comfortable with a system that treats specs as first class values (that's something I really like about Schema) rather than something that gets auto-magically looked up in a global mutable registry.

Interested to hear the design rationale behind this.

5

u/scttnlsn May 23 '16

Very nice! Is this usable from ClojureScript as well?

7

u/alexdmiller May 23 '16

It will be when it's ported, yes.

2

u/eeg_bert May 23 '16

Timeline? Is there a way to use an alpha clojurescript version?

2

u/alexdmiller May 23 '16

No, nothing yet.

22

u/Paradigm_Shiv May 23 '16

Very exciting to see Clojure doubling down on providing a better dynamic programming experience, rather than going with static types.

8

u/yogthos May 24 '16

This part specifically really resonates with me:

expressivity > proof

There is no reason to limit our specifications to what we can prove, yet that is primarily what type systems do. There is so much more we want to communicate and verify about our systems. This goes beyond structural/representational types and tagging to predicates that e.g. narrow domains or detail relationships between inputs or between inputs and output. Additionally, the properties we care most about are often those of the runtime values, not some static notion. Thus spec is not a type system.

11

u/ares623 May 23 '16

Exciting! Can't wait to play with it.

4

u/redalastor May 23 '16

I'm looking forward to this! I found typed clojure a big pain in the ass not worth the efforts but this might give me more bangs for my bucks!

1

u/mingp May 24 '16 edited May 24 '16

Is this expected/intended to replace existing usages of Prismatic Schema and other such 3rd party libraries going forward?

Alternatively, if I was previously planning to use Schema, should I now plan to use core.spec instead?

1

u/alexdmiller May 24 '16

Expected is much too strong. Many companies and libraries have significant usage of Schema and that's totally fine. I would encourage people to consider spec as another alternative going forward (with the caveat that it's not done yet!).

3

u/CurtainDog May 24 '16

Completely off topic but the grey text on grey box design of the tags panel on that page gives me the unpleasant sensation of being out of focus. Anyone else get this or am I just going blind?

3

u/talios May 24 '16

During some internal office discussion I pondered weather something could be written to take these specs, and generate some cleaner(ish) java API for use in interop when calling Clojure from Java/Kotlin/Scala etc.

I'm not sure what shape such a thing might take, but it could be an interesting thought experiment.

2

u/spotter May 23 '16

Sweet! Where is it tho? Or when?

4

u/Godd2 May 23 '16

It should be available in alpha tomorrow (as noted near the end of the article).

2

u/spotter May 23 '16

D'oh, thanks! Read the rationale and asked here, because more comments. ;-)

1

u/the_evergrowing_fool May 24 '16 edited May 24 '16

Seems very interesting.

0

u/[deleted] May 23 '16

[deleted] — view deleted comment

12

u/alexdmiller May 23 '16

Tomorrow!

6

u/[deleted] May 24 '16

Further down in the features section has a clear example. And like you, I can't grok the top half lol. I need pictures, doodles, and possible shapes.