3 ms·
YAML is probably the least ergonomic configuration format available. [1] Even XML would be preferable, as at least most XML parsers are interchangable. [1] htt
by edejong 7y ago
YAML is probably the least ergonomic configuration format available. [1] Even XML would be preferable, as at least most XML parsers are interchangable.
[1] https://www.arp242.net/yaml-config.html https://www.arp242.net/yaml-config.html
- jrockway 7y agoI don't think YAML is the least ergonomic configuration format available. It has comments, unlike JSON. YAML's super clever upgrading of strings into other types is irritating ("foo: yes" is type {foo boolean}). Indentation-based semantics are not for everyone, and I think most of us would not mind the "noise" of braces. Other than that it's pretty OK. It's easy to write code that reads and writes it. It's very easy to read. It's above average but not prefect for writing (again, braces are pretty okay, not sure why they went the indentation route). I agree with the article you linked that a lot of YAML implementations in scripting languages do dumb things like letting you put code in the file, and they all parse their special features differently. A config format does not need to be portable; while all these implementations do different things, they follow a format that continues to allow something to parse the entire file. So you can write an auto-formatter in Javascript (prettier) even though a Go program (kubectl) is going to actually read the file, and it all works. I have used many other formats for config files. They all suffer from their fair share of problems. TOML/INI handles nesting very poorly (making you retype the names of all parent keys). JSON doesn't let you write comments or trailing commas, so it's hard to work on in your editor (running prettier on save fixes the trailing commas though). Text protobuffers are great but people look at you weird when you use them. XML is a travesty. It is hard to write and hard to parse. It does all sorts of confusing things that humans do not expect, so it's really more of a binary format for computers to use than a text format for humans to write. (Remember, the XML spec says: <foo> bar </foo> is different from "<foo>bar</foo>" even though humans think they're the same.) XPath querying is great, I love it. But we have "jq" now that works on JSON and YAML. Anyway, I think YAML is basically a fine format for config files. Perfect? Nope. OK? Yup. I will happily read or write a YAML file in a computer program or by hand. It's pretty OK.
- 0xffff2 7y ago> It's easy to write code that reads and writes it. This is where you lose me. AFAICT, no two YAML parsers agree on what YAML is, so it's actually very hard to write code that reads and writes YAML because it has to be carefully tailored to work with whatever other YAML parsers are in your toolchain.
- jrockway 7y agoI agree that you won't end up with a compatible data structure in every language, but you can read it in and write out a semantically-identical document, which is nice.
- throw0101a 7y ago> I don't think YAML is the least ergonomic configuration format available. It has comments, unlike JSON. This is because JSON is not a configuration format but a machine-to-machine data exchange format. Using it for configurations is using it for something it was not designed to do. And comments were left out of JSON on purpose: > Comments were purposefully excluded from JSON. In 2012, Douglas Crockford described his design decision thus: "I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability." [27] * https://en.wikipedia.org/wiki/JSON#Data_portability_issues https://en.wikipedia.org/wiki/JSON#Data_portability_issues