by usrbinbash · 2y ago · 0 comments
I have no idea why people started using it. "bUt jSOn dOeSn'T HaVe cOmMenTS" ... oh gimme a break! You want a comment in JSON?
{
"//": "This is a comment explaining key1.",
"key1": "value1",
"//": "This is a comment explaining key2.",
"key2": "value2"
}
There. Not so hard. Writing a config parser that just ignores all keys starting with "//" is trivially easy...if it's necessary to ignore them at all that is, because most config parsers I have seen couldn't care less about unknown keys, let alone repeated keys.So what other "reasons" were there for YAML?
Oh, the human readbility thing. Yeah. Because syntactically relevant whitespace is such a joy in a data serialization format. It's bad enough when a programming language does that (and I am saying this as someone who likes python), but a serialization format? Who thought that would make things easier?
And then of course there are other things filled with joy and happiness...like the multiple ways to write "true" and "false", because that's absolutely necessary for some reason.
"Oh but what about strict-yaml?!" I hear the apologies coming...great, so now I have the ambiguitiy of what parser is used on top of the difficulties introduced by the language itself. Amazing stuff. If that's the solution, then I'd rather not have the problem (aka. the language).
But despite all[1] these[2] problems[3] and more, YAML somehow became the goto language for configuring pretty much everything in DevOps, first in containerization, then in cloud, and everything in between. And as a result, we now have to make sure our config template parsers get whitespace right. Great.
So bottom line: The problem here is maybe 1/3 the complexity of config files and 2/3rd the fact that YAML should have never been used as a configuration format in the first place. It's benefits are too small, and it's quirks make too many problems for that role, outside of really trivial stuff like a throwaway Dockerfile.
Want config? Use JSON. And if you need something more "human friendly", use TOML.
[1]: https://github.com/cblp/yaml-sucks
[2]: https://changelog.com/posts/xml-better-than-yaml
[3]: https://noyaml.com/
key1=value1 # this is a proper key1 comment, if you move a line, it stays with key1
key2=value2 # it also doesn't break the table
# and you don't need to write a config parser
# nor modify a syntax highlighter
# nor make sure other people use your comment style
Given a choice, I'd even opt XML over YAML.
No, you were pointing out that some people won't like that solution. Which is completely fine. And yes, that solution is ugly as hell, and it is a dirty hack, and I don't recommend actually doing that if there is a better way (like TOML).
But it does work.