5 ms·
The problem is very specifically the fact that YAML, as a config language, sucks. I have no idea why people started using it. "bUt jSOn dOeSn'T HaVe cOmMenTS"
by usrbinbash 3y ago
The problem is very specifically the fact that YAML, as a config language, sucks.
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 https://github.com/cblp/yaml-sucks
[2]: https://changelog.com/posts/xml-better-than-yaml https://changelog.com/posts/xml-better-than-yaml
[3]: https://noyaml.com/ https://noyaml.com/
- eviks 3y agoThat ugly child doesn't cut it, these are the comments people want: 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
- usrbinbash 3y agoIf people absolutely want those, they can use TOML, which supports single line and inline comments. Given a choice, I'd even opt XML over YAML.
- eviks 3y agoThat's fine, you can pick whatever XML ugliness you like, I was just pointing out that you can't solve the basic fail of JSON with comments by making them data
- usrbinbash 3y ago> I was just pointing out that you can't 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. https://www.youtube.com/watch?v=C5kGCwJ25Yc https://www.youtube.com/watch?v=C5kGCwJ25Yc
- eviks 3y ago> ugly as hell, and it is a dirty hack, and I don't recommend actually doing that you're just paraphrasing the obvious - it's not a solution. And YAML is a better way and addresses the problem you choose to ignore as such - ugliness.
- usrbinbash 3y ago> And YAML is a better way and addresses the problem you choose to ignore I haven't ignored it, as shown by us discussing it here. And no, YAML isn't a better way. It does commenting better, true, and at the same time, it does so many things wrong, that are absolutely no problem in JSON, that it becomes a treatment worse than the disease.
- eviks 3y ago
- deleted 3y ago[deleted]