6 ms·
In exchange you get incredible validation of your JSON and precise error messages about missing fields etc. And you don't have to write that bit by hand: http
by amimetic 9y ago
In exchange you get incredible validation of your JSON and precise error messages about missing fields etc.
And you don't have to write that bit by hand:
http://eeue56.github.io/json-to-elm/ http://eeue56.github.io/json-to-elm/
will generate the decoder for you for straightforward cases and give you a great starting point for more complex cases.
You also get proper ADTs to manage state: not asked/loading/loaded/error something that is tedious and error prone in Javascript.
- dmitriid 9y agoYup. There are a bazillion libraries now trying to pretend to make it look like it's easy to deal with JSON in Elm. An online converter is definitely not something I would advertise for a "production-ready highly productive amazing pragmatic language to be used in a serious company"
- dmitriid 9y agoFor god's sake, Elm is the only language I know that has _an entire book written on how to handle JSON_: https://www.brianthicks.com/post/2017/01/06/announcing-the-json-survival-kit/ https://www.brianthicks.com/post/2017/01/06/announcing-the-j... It's introduction is: "You know how it takes so much effort to produce even the simplest of programs when JSON parsing is involved? Wouldn’t it be nice if you could breeze right on by that step and get on with writing your business logic? This is what you’ll get with The JSON Survival Kit, a short ebook on JSON decoding in Elm." Wut
- Skinney 9y agoAnd Go has an entire book on how to use the database/sql package. Does that mean the database/sql package is hard? Is React difficult because there is online courses? Is Bootstrap? Of course not.
- enalicho 9y agoIt is no different from using a code generator for anything. Json2elm is designed to _help you_ write decoders, not replace decoders. Once you know how to write them, json2elm is mostly useful for generating boilerplate.
- dmitriid 9y agoIf you need a code generator to generate boilerplate... something's wrong with your language
- ch4s3 9y agoI suppose you start every new project with mkdir and a few touch commands? In all seriousness, ever language has boilerplate. In js it might be error handling and state management. In Elm, its decoding json.
- dmitriid 9y ago> I suppose you start every new project with mkdir and a few touch commands? This is not a valid analogy (and no analogy is ever valid). > In js it might be error handling and state management. In Elm, its decoding json. Yeah, and Go has trouble with generics. It doesn't mean it's a feature that has to be vigorously defended. Especially if it's basically the very first thing anyone will have to do in any web application in a language that is meant for client-side web programming
- ch4s3 9y ago> It doesn't mean it's a feature that has to be vigorously defended. I'm not sure anyone is defending it. At least, I'm not. Basically Elm's compromise is safety, and less runtime complexity then Haskell. The trade off there is boilerplate. As with most things, there is no free lunch. I've stopped using Elm precisely because of these issues, but I understand why Evan made the choices he did.
- KirinDave 9y agoSo... you don't use yo/yeoman? At all?