spec-tools icon indicating copy to clipboard operation
spec-tools copied to clipboard

Thoughts about fdef utils?

Open vincentjames501 opened this issue 8 years ago • 6 comments

Just wanted to stir up a conversation about this. I personally find specing functions to be tedious for most, simple functions.

Assume we had this spec:

(ds/spec ::user {::id   spec/uuid?
                 ::age  spec/pos-int?
                 ::name spec/string?})

Assume we want to spec this function:

(defn teenager?
  [user]
  (<= 13 (::age user) 19))

It would be neat if we could somehow spec this function easier

(ds/specf teenager? 
  [::user] ; args
  spec/boolean? ; ret
  nil ; fn
)

Or even with a Schema like macro:

(ds/defn teenager? :- spec/boolean?
  [user :- ::user]
  (<= 13 (::age user) 19))

I haven't actually fleshed out any of my thoughts, just wanted to see what you thought about some function specing utilities.

vincentjames501 avatar Aug 22 '17 16:08 vincentjames501

Hi. There is a similar discussion in the Schema repo: https://github.com/plumatic/schema/issues/366 I think the schema-syntax would be great for spec too.

ikitommi avatar Aug 22 '17 17:08 ikitommi

I personally like the macro approach as it makes it easier to look at one place and see the semantics of the function. I'd rather just cover the simple/common cases and if the user needs something more advanced they should just use fdef or something more low-level directly.

vincentjames501 avatar Aug 22 '17 19:08 vincentjames501

+1 !!!!!!!!!

pablobcb avatar Aug 22 '17 19:08 pablobcb

Related: https://groups.google.com/forum/m/#!topic/clojure/0wqvG2sef8I

The goal is to add the macro to orchestra, as a tool to help encourage spec'ing all functions.

ikitommi avatar Sep 24 '17 16:09 ikitommi

Also see https://github.com/Provisdom/defn-spec

metametadata avatar Jun 12 '18 01:06 metametadata

Related: https://github.com/plumatic/schema/issues/366#issuecomment-1008284317

ikitommi avatar Jan 09 '22 12:01 ikitommi