This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-22
Channels
- # announcements (3)
- # babashka (6)
- # beginners (29)
- # calva (10)
- # cider (14)
- # clj-kondo (67)
- # cljfx (6)
- # clojure (34)
- # clojure-australia (1)
- # clojure-europe (46)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-spec (6)
- # clojure-uk (27)
- # clojured (1)
- # clojurescript (26)
- # conjure (14)
- # cursive (5)
- # data-science (1)
- # datomic (26)
- # deps-new (10)
- # editors (1)
- # events (2)
- # fulcro (23)
- # graalvm (41)
- # honeysql (5)
- # introduce-yourself (1)
- # jobs (1)
- # jobs-discuss (1)
- # luminus (2)
- # malli (22)
- # meander (5)
- # observability (3)
- # podcasts (1)
- # rdf (3)
- # re-frame (27)
- # remote-jobs (7)
- # reveal (6)
- # shadow-cljs (45)
- # xtdb (8)
What's the recommended location for function schema definition? Should it be on the same namespace as the function or in a separate namespace?
No strong opinions in malli for that. My favourites:
1. Inlined (the plumatic syntax)
2. just before the functions (`m/=>` is as long as defn
, looks good
Someone reviewed my code that added m/=>
for each and every function in the core namespace of a lib (around 10 functions) and he thought it was polluting the namespace
I tend to prefer to have the schemas near the code as schemas serve also as documentation
I prefer the Plumatic style as it's more about upfront (meta) data expression, m/=>
feels unnecessarily clever and sort of indirect/IoC hellish since it comes after the function declaration. But that's just my two cents 🙂
+1 for this. Being able to place the schema right near to the argument is way more intuitive and maintainable than having them separate from each other.
^{::m/aspects [(contract [:=> [:cat int? int?] string?])]}
(m/defn some-fn [x y]
(str (+ x y))
Does malli support plumatic style? how?
I'm wondering whether function metadata maps may be suited to this purpose, the way spec
does with :pre/:post
validation inlined in an ordinary defn
form, without needing a macro for function definitions. There may be a good reason to not overload the "canonical" keywords and instead use something like :malli/schema
to inline it, but having it right in the form using metadata allows tests to be easily derived from a self-describing function with meta
.
https://clojure.org/guides/spec
Was there something in your experience with spec-tools
that led you to believe this isn't a good idea or the optimal solution for malli
?
the plumatic syntax has been out since 2013 and I believe it's the most used syntax, by far. I have used it, it's just good.
I like also the`:malli/schema` suggestion, the malli.instrument
could be configured to support multiple sources like:
1. the =>
registry
2. the :malli/schema
metadata
3. plain old function schema inferrer
@ikitommi In your previous message, you wrote:
> just before the functions (`m/=>` is as long as `defn` , looks good
What do you mean by m/=>
before the function?
In malli's README, m/=>
comes after the function definition
this works too:
(m/=> plus [:=> [:cat [:* :int]] :int])
(defn plus [& ns] (apply + ns))
(plus 1 2 3)
; => 6
Nice. In fact malli treats function names as symbols
So it doesn't matter if you create the schema before the function is defined
+1 for this. Being able to place the schema right near to the argument is way more intuitive and maintainable than having them separate from each other.
I'm wondering whether function metadata maps may be suited to this purpose, the way spec
does with :pre/:post
validation inlined in an ordinary defn
form, without needing a macro for function definitions. There may be a good reason to not overload the "canonical" keywords and instead use something like :malli/schema
to inline it, but having it right in the form using metadata allows tests to be easily derived from a self-describing function with meta
.
https://clojure.org/guides/spec
Was there something in your experience with spec-tools
that led you to believe this isn't a good idea or the optimal solution for malli
?