malli

https://github.com/metosin/malli :malli:
Stefan 2020-09-17T09:53:59.225900Z

Hi all, somebody pointed me to Malli (thx @borkdude @hobosarefriends) because of the situation with spec being alpha and spec2 on the horizon. But then I noticed in the Malli readme that it says: “Pre-alpha”, which scares me a bit. Can somebody clarify the situation and whether or not this is a good time to start using Malli? Our situation by the way is that we have a big existing codebase without any sort of spec/schema, so in that respect we’re starting from scratch.

2020-09-17T11:02:52.230200Z

@ikitommi A small heads up I have generated a Malli spec that can validate all of our cfn templates (around 30, pretty big and complete). I’ll try to publish it soon and point to some pitfalls. One thing that is hard to debug are (deeply nested) recursive schemas. Without the use of [:ref …] it will give a stackoverflow error without a good pointer. And I had to do a trick in the :multi dispatch to prevent :invalid-type errors and to stay compatible with spell-check. All in all it works pretty well! Thanks

2020-09-17T11:11:32.230500Z

All the solutions are officially still alpha. Trying any of them is a good learning experience. If you don’t have specific requirements, I would suggest to start with clojure.spec (1) as it has the most examples and documentation. I think Malli is modelled like spec(2) so any learnings with clojure.spec will be applicable later in malli

borkdude 2020-09-17T11:15:09.230700Z

Although @ikitommi mentioned that the goal of the current Clojurists Together funding is to make a stable (non-alpha) release?

borkdude 2020-09-17T11:16:31.231700Z

With spec it remains to be seen. It's been in alpha for over 4 years.

ikitommi 2020-09-17T11:17:27.232600Z

@stefan.van.den.oord Just checked that last bullet on “last things before initial stable release” yesterday. will clean up corners and will ship the alpha, most likely next week.

ikitommi 2020-09-17T11:18:49.234700Z

the public api has been mostly stable since june, there has been small changes in the advanced user / extender api, and most likely will be after the first release.

borkdude 2020-09-17T11:19:25.236Z

@ikitommi (Note my remarks on borkdude/dynaload. I'm currently solving a problem with GraalVM. Using resolve at runtime bloats the binary with +20MB. But it does work.)

ikitommi 2020-09-17T11:19:25.236100Z

1.0.0 might be soon too, after feedback from the community.

ikitommi 2020-09-17T11:20:24.237Z

@borkdude sorry, read you message, but didn’t have time to answer. There is no GraalVM tests atm, should be.

borkdude 2020-09-17T11:20:48.237400Z

I will publish dynaload 0.2.0 or so that will have breaking changes to fix this problem, but I'll notify you

borkdude 2020-09-17T11:20:52.237600Z

and possibly make a PR

ikitommi 2020-09-17T11:21:24.238200Z

that would be great! GraalVM support is top priority, don’t want bloated binaries 🙂

ikitommi 2020-09-17T11:22:49.240300Z

when writing libraries, the goals matter a lot. few years ago, didn’t know much about perf. can’t add that later. now, the cljs bundle size, learned how to handle that. Next: GraalVM as a target.

borkdude 2020-09-17T11:22:52.240600Z

yeah. I have a dynaload-graal-friendly branch, with script/graal-test. currently this code still bloats:

#?(:clj (defn resolve* [sym]
          ;; TODO: this adds + 20MB to the GraalVM binary
          #_(let [ns (symbol (namespace sym))
                v (symbol (name sym))]
            (when-let [ns (find-ns ns)]
              (.getMapping ^clojure.lang.Namespace ns v)))))
so it's either in find-ns or in the namespace interop

borkdude 2020-09-17T11:27:20.240800Z

yeah, it's the namespace interop

borkdude 2020-09-17T11:28:37.241200Z

I think using this interop will make GraalVM think it should hold on to more that it actually needs

2020-09-17T11:28:52.241300Z

Good point 🙂

borkdude 2020-09-17T11:30:02.242300Z

so what we can do is only resolve at compile time. The user should take care of requiring the lib namespace before they load the dynaloaded code, else it will be considered not there.

ikitommi 2020-09-17T11:32:43.243700Z

is there a :preload thing with deps? other than the -e from command line?

borkdude 2020-09-17T11:33:31.244100Z

no

ikitommi 2020-09-17T11:33:32.244200Z

have this on my project Justfile:

# start backend nrepl
@backend:
    clj -A:dev:test:common:backend -e "(require '[hashp.core])" -m nrepl.cmdline -i -C

borkdude 2020-09-17T11:34:50.244900Z

for graalvm builds with deps.edn that may work

borkdude 2020-09-17T11:35:00.245300Z

with the lein + uberjar approach it may not

borkdude 2020-09-17T11:35:45.246400Z

just take care in your main to require those libs first, then it will be solved. we can make this behavior graalvm only for example by reading an environment variable or java property

ikitommi 2020-09-17T11:37:20.247600Z

where is borkdude/am-i-in-graalvm library?

ikitommi 2020-09-17T11:38:22.248400Z

so: 1. cljs: preload or direct require 2. jvm: just in a classpath 3. graalvm: direct require , right?

ikitommi 2020-09-17T11:38:44.248700Z

or: 2. jvm: just direct require

ikitommi 2020-09-17T11:40:10.249600Z

can one differentiate if the lib is required or just in the classpath in 2? could be an option in dynaload?

borkdude 2020-09-17T11:41:54.251200Z

@ikitommi 1) I think in CLJS the order of require doesn't matter, because the check happens at runtime at the first deref. 2) this works because CLJ has runtime require 3) Like 1, but now the order matters, since we check at compile time, before the deref. About checking the classpath: not sure how this would look. That's kind of the same as compile time resolve.

borkdude 2020-09-17T11:44:34.251800Z

Checking whether you are in a GraalVM binary already works, but that's too late. You have to check at (Clojure) compile time.

borkdude 2020-09-17T11:49:32.252700Z

So based on setting -J-Dborkdude.dynaload.target=graalvm-native we could alter the behavior or 2 to 3

borkdude 2020-09-17T11:50:17.253300Z

or -J-Dborkdude.dynaload.resolve-time=compile

eskos 2020-09-17T13:35:04.253600Z

re: graalvm library, shouldn’t that be called antioch ?)

2020-09-17T14:54:41.254Z

(now public)

2020-09-17T14:56:57.254200Z

Maybe useful information; I’ve reduced the usage of :or and used :multi instead to prevent super long lists of errors (reduces branching factor)

2020-09-17T14:57:30.254400Z

I think I broke proper spell check feedback by not using a keyword as dispatch function. I’ll look into this soon again

rschmukler 2020-09-17T20:28:03.254700Z

There's some discussion on github that might be interesting: https://github.com/metosin/malli/issues/207

borkdude 2020-09-17T21:31:17.255600Z

@ikitommi Pushed dynaload 0.2.1 with better support for GraalVM binaries: https://github.com/borkdude/dynaload#graalvm

1🎉