Thoughts on generating JSON decoders

783 views
Skip to first unread message

Evan Czaplicki

unread,
Oct 18, 2017, 8:36:41 PM10/18/17
to elm-dev
A lot of folks are frustrated by having to write JSON decoders.

First, I think the idea of generating JSON decoders is based on an incomplete view of data interchange formats. I do not think the historical examples support that theory, and I wrote about it extensively here:

Please read that.

Second, I have found ways to make the compiler more helpful when you are running into decoder issues.

My personal theory is that decoders make a lot more sense if you learn about them from the official guide. Specifically, things go better if you learn about Maybe, then Result, then Decoder.

Not everyone reads that document though, so the compiler now detects type mismatches that involve the Json.Decode.Decoder type and gives a link to documentation that explains how it all fits together.

I think it is plausible that folks end up wasting hours or days stuck at this exact moment, and it is really not clear where to go to learn the necessary information right now. I plan to explore this theory by releasing the improved error messages with 0.19.

Finally, I think it makes sense to explore points (1) and (2) fully before deciding that the language should be more complicated. I understand that not everyone agrees with this kind of strategy, but I think it has served Elm well so far and plan to continue using it. 

Christian Charukiewicz

unread,
Oct 23, 2017, 2:02:29 PM10/23/17
to elm-dev
Thanks for sharing Evan.  As someone who leads a team using Elm at work, where development time and language learning curves do matter, I still I absolutely agree with you.  Complicating the language to appease the people complaining seems shortsighted.

However, I will say that the Elm community should be upfront about the fact that JSON decoding in Elm requires more work than it does in JavaScript (or most other langues). This message should always come with a mention that this extra work comes with significant benefits (type safety, control, flexibility, etc). I personally do not like seeing when the response to "decoding JSON is hard" is "here use this decoder generator tool" without any mention of actually learning how it works, as this is counterproductive in the long run. I think improved compiler messages are a step in the direction of emphasizing learning over just getting it done.
Reply all
Reply to author
Forward
0 new messages