Fork me on GitHub
Ben Sless08:08:19

hot take: :fn schema should be deprecated


why is that?

Ben Sless09:08:52

95% of the instances I saw it used the programmer should have used properties or defined a -simple-schema

Ben Sless09:08:31

It is used in a way too general manner, usually one which impairs serialization and generation

Ben Sless09:08:56

We can write guides and improve documentation and give workshops and do backflips and pay for ads on the superbowl, people will still use :fn because it's easy

Ben Sless09:08:58

generators and transformers suffer from this, big time

Ben Sless09:08:13

And it makes the code opaque

Ben Sless10:08:37

I did say this was a hot take 🙃


I think -simple-schema is not always what you want to do. And yes :fn is pretty handy, especially if you don't need transformers and generators but only validation. I'm not sure it would be a good move to force people to use -simple-schema just for validation (e.g. involving two or more map entries).

Ben Sless11:08:23

This is absolutely me speaking from frustration, not a definitive or proscriptive solution

😂 2
Ben Sless11:08:53

The problem isn't using fn but using it where [:string {:max 10 }] would do

Ben Sless11:08:11

I also see predicate functions used a lot where decoders would be better


Ok, make total sense now. I just took it as a proposal of change. I need to develop a sense of humour I guess 😅

Ben Sless15:08:36

See the "hot take" prefix


I missed that :face_palm:😅

😄 2
Ben Sless15:08:18

Frustrated by half a day fighting with badly written and used malli schemas Everything can and will be abused


I don't know you particular case, so just guessing... Maybe organising some internal training showing how to use Malli could avoid that kind of tool misuse in the future 😉🚀

Ben Sless16:08:05

I am actually working on internal training which I hope I'll be able to release mostly as a contributed getting started guide

🚀 4
Noah Bogart15:08:31

I suspect this also has to do with docs. It can be hard to fully enumerate the possibilities of a given API, and something like :fn just works.


I agree with this point. @UK0810AQ2 tbh with you, I understand the points that frustrates you, but I wouldn't be two weeks ago. The thing is that Malli is nice to use once you know it, but it is fairly confusing when you start. I think that it might be the source of the problem, that people are using the simplest solutions they know, because they simply don't know all the features of the tool. Let's take my example. I used spec before, but haven't used nor prismatic schema. Some of the concepts were simply new to me. E.g. transformers, there are at least four ways of transforming values with Malli, and it is not obvious what they are and how they work. I discovered it by reading the docs, examples, Malli impl and reading the Tommis answers here. I don't have daily job and I could invest a bit of time, still not everyone can afford that much of investment, so most of the time, I guess, people pragmatically makes things done 🙂 In this particular topic, using Malli transformers, I intend to make a comprehensive writing at some point to make the process easier for others. I think in case of :fn and simple-schema case is the same, people might not be aware when/where to use what 🙂

Ben Sless16:08:08

I agree. Malli's docs are comprehensive but like man pages they don't tell you where to start, they don't guide you towards "I want to do X"

👍 4

is there a more idomatic way of defining a map that must have a key but the value can be nullable. Here's what I've currently got:

(defn ? [predicate] [:or predicate nil?])

(def MyThing
      [:someValue (? string?)]])


Only reason I want to force the existence of a key so it appears in a JSON response with null as it's value


I'm not 100% sure but would that not be [:someValue [:maybe string?]]


oh, I didn't realise there's a [:maybe]


yep that works, ty 🙂


my experience with malli so far has been quite positive