This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-05
Channels
- # beginners (46)
- # calva (89)
- # cider (24)
- # clara (7)
- # clj-kondo (36)
- # clojure (33)
- # clojure-australia (4)
- # clojure-dev (9)
- # clojure-europe (15)
- # clojure-israel (1)
- # clojure-nl (1)
- # clojure-uk (13)
- # clojurescript (55)
- # community-development (38)
- # conjure (1)
- # cryogen (12)
- # cursive (16)
- # data-science (4)
- # datomic (39)
- # events (2)
- # fulcro (5)
- # gorilla (3)
- # introduce-yourself (3)
- # jobs (9)
- # kaocha (5)
- # malli (16)
- # music (12)
- # off-topic (11)
- # polylith (4)
- # react (4)
- # reactive (1)
- # reagent (18)
- # remote-jobs (2)
- # reveal (2)
- # sci (4)
- # shadow-cljs (31)
- # timbre (4)
- # tools-build (70)
- # tools-deps (11)
- # vim (33)
- # xtdb (53)
I could not get my head arround the best practices to use Malli for runtime checking of function parameters. I saw the docu about this, but wonder between "instrumentation", which seems to be dev oriented,
vs call validate
in the code
I store my schema as function metadata if this helps.
How do people do this ?
When working with Malli we used it to test all API inputs to the system and sometimes the outputs from the system. We didn't use it to check common function calls. Why do you want to do that?
for development it’s very nice to see when you meant to pass in a vec and passed in a map instead, but in prod i feel like those kinds of checks aren’t helpful (especially if the code actually runs how you expect anyways)
I can see that though I usually accomplish those types of checks through my tests. It'll be interesting to see in anyone has a technique for using Malli for environment based assertions.
@danielglauser it’s layered: malli.instrument
can be used in prod too, it doesn’t contain any var-watches, clj-kondo emitting and thanks to it’s filters, you can annotate your functions with meta like {:malli/always-validate true}
and instrument those in prod.
have worked with a lot of codebases with Plumatic Schema where few (important) functions had the :always-validate
on. e.g. when reading data from document-db or just Very Important Function (handling money) where the perf penalty is ok.
malli.dev
is built on top of malli.instrument
with just start!
and stop!
, which both are stateful. would not use in prod.
I think "input checking" at runtime can be important for public functions. At the end, I only guarantee that my function works, if the caller does his part (giving valid input only). Failing so, resulst often in very ugly error message deep in Clojure, from which it is impossible to read what I have done wrong (as teh caller).
"Output" checking is a complete different story. That I probably don't want to have in production code.
Is somebody doing this ? I see various way to implement the parameter checking, and was wondering which works best. 1. Instrumenting
2. direct calls of format
Together with this come the different options, where to keep the schema ? as defn metadata or in some vars ? How can we the use those easely for documentation of a function ?