5 ms·
The real question is why are we using yaml at all?
by MrStonedOne 8y ago
The real question is why are we using yaml at all?
- quickthrower2 8y agoBaffles me. I don't like any language or file format where whitespace matters. Even Haskell bothers me in this regard. To me white space shouldn't add cognitive load. I want to look at the symbols not the formatting of the antisymbols to understand what is going on. Write JSON and use your editor tools to format it with nice indentation, and you are sweet! That said Yaml makes an excellent format for reading, but not for writing.
- amanzi 8y agoWhite space matters with Python but I rarely run into issues with indentation in Python. But YAML on the other hand, I have nothing but nightmares.
- kccqzy 8y agoI have the same experience. I just think think it is possible to design easy-to-write indentation-sensitive formats but YAML is not. For example is always baffles me that a: - b - c has a list inside an object but the list is not further indented. There's in fact a hierarchy relationship but absolutely no indentation.
- Rapzid 8y agoYou can indent it though, but the hyphen already means a list item. That is a preferred syntax for many that are used to YAML though.
- kccqzy 8y agoThat's kind of my point. Indentation is optional, so many don't indent, making the resulting document harder to understand.
- emmelaich 8y agoFWIW, I think yaml / ansible linters and style checkers typically require indentation.
- XorNot 8y agoThe hyphen is associated with the a though. In what's posted, a is a list, not a map - the type of the parent is being declared by that hyphen.
- mikepurvis 8y agoThat's at your option, though. It's perfectly valid yaml to indent the list as many spaces as you want.
- setr 8y agoI think its because python has very strict and very simple indentation rules (a nested block must be indented, and the file requires consistent indentation. Is there anything else?) YAML gives you options, or varies necessity somewhat arbitrarily on the structures, which is (marginally) good for reading, but a lot of headache in writing
- wolph 8y agoI personally love Python where whitespace matters a lot too. But I regularly find myself fighting with the whitespace in yaml for some reason. To me yaml (especially with templating) seems like a very contrived way of avoiding having to program, while still effectively programming. I much prefer json, or if more intelligence is required, actual javascript objects. The only big downside of json where yaml does shine is the support for comments within your files.
- crdoconnor 8y agoI never quite understood this attitude. Not treating whitespace as meaningful means it's necessary to have a longer, syntactically noisier file. That's fine if you're primarily concerned with computers exchanging data (JSON) but where readability and writability matters, extra syntactic weight is a headache. I can't imagine writing JSON by hand but I write plenty of YAML by hand every day without issues.
- quickthrower2 8y agoBecause deleting a tab could entirely change the meaning of the file, breaking everything, with no compile time errors. IDE tooling or linting might go somewhat to make me more comfortable with YAML.
- emmelaich 8y ago> I don't like any language or file format where whitespace matters. .... To me white space shouldn't add cognitive load. 1. there is no language where whitespace does not matter 2. the very purpose of indentation is to ease cognitive load. Now, you may not want it to be inflexible or mandatory but your argument needs elucidating.
- quickthrower2 8y agoOk: I don't like any language of file format where the regex s/\s+/\s/g would change the meaning of the program except in parts of the program within string delimiters, except for the parts of string delimiters which contain literal code e.g. ins ES6 `Hello ${world}`.
- emmelaich 8y agoOK, but I'd restrict the set even more to exclude voluntary indentation. I mean, you'd want that caught by style checkers anyway, even if the language didn't require it. So we're left with the cases where you'd like compact code / one-liners but are forced to use multiple lines for language syntax reasons. I'd say that that's a pretty small set of cases and long way from the phrase "I don't like whitespace sensitive languages" which you (and many others!) use. I conceded it can be annoying in Python and I do wish there was an escape route sometimes.
- andybak 8y agoSo you prefer languages way that regex only appears to change the meaning? Non-semantic white space can be deceptive. Semantic whitespace isn't.
- h1d 8y agoExperienced programmers use decent editors to indent their code anyway but at least you don't see codes with indentation going left and right at random locations with Python.
- nightfly 8y agoI've taken the strategy of emitting JSON, but accepting YAML input (maybe a restricted subset in cases where it's untrusted data). YAML can function as a super-set of JSON, so you can have comments in hand-written/modified data this way while emitting a simpler to parse data format.
- mixmastamyk 8y agoIt's a lot easier for end-users to read and write by hand. If that is not a requirement, a simpler machine-friendly format is likely better.
- amanzi 8y agoWriting YAML is not easy for end-users. The indentation--especially in large files--is really difficult to keep track of, and some really basic stuff like when to quote strings is not consistent at all.
- mixmastamyk 8y agoNope, indentation is not a problem with indentation guides. A misplaced comma in a JSON file however kills it, gets me every time I have to write it by hand. Also, it is true YAML has too many features, though I find they are typically ignored or disabled.
- krapp 8y agoA misplaced comma is also not a problem in an editor with syntax highlighting, but between the two, indentation could take longer to fix.
- mixmastamyk 8y agoSyntax highlighting doesn't count commas. The problem is JSON doesn't allow trailing commas, so adding or reordering frequently results in a difficult to diagnose error.
- krapp 8y agoFinding out if a set ends in a comma or not still makes it easier to debug than YAML.
- mixmastamyk 8y ago
- IshKebab 8y agoI think it is partly momentum - at this point most CI systems use YAML in spite of its insanity - even Azure Pipelines! And partly it's because the syntax for multiline string literals is very minimal, which is kind of a nice feature for CI since you tend to have a lot of them. It's still insane though. TOML is much more reasonable.
- Rapzid 8y agoThe best thing that ever happened to Cloud Formation was the new YAML syntax. Writing YAML is easy with a good editor like VSCode. Install the YAML code outline extension for sugar; works great for OpenAPI specs. YAML flow style offers some good options for keeping the file compact.
- SamWhited 8y agoI'm all for good editor support, but you shouldn't need it to write a simple document. Complicated editors should be supporting tools at best, because you won't always be in a position to use one. The things we write should be simple enough to be written and understood by hand with minimal mistakes (then we can make it even easier in some cases using nice editors and tooling).
- shirakawasuna 8y agoI don't think I've ever used anything under than vanilla vim for editing YAML files... with next to zero issues. The problem for me is that the multiple ways to do the same thing result in something that's pretty opaque to clear specifications that aren't just very simple examples / structures.
- SamWhited 8y agoMe too, except it's just always wrong the first time… drives me nuts. Maybe it's just me.
- atsjie 8y agoAnyone working with cloudformation would wonder why we ended up writing json?
- jszymborski 8y agoI really like TOML as a compromise between "looks pretty" and "parses well". That being said, I find it funny that the author is crying afoul, saying that YAML isn't as well suited to be templated as JSON is, when XML had schemas sorted out ages ago. People ran away from XML, saying it was this verbose, ugly, bandwidth hungry (back when we were sending XML over AJAX) behemoth (which it totally is)... but I think when your usecase is complicated enough to worry about templating, you should take a hard look at XML and ask whether it might suit your better.
- deathanatos 8y agoEasier to read and write than JSON. JSON requires constant quoting, can't support multiline strings, has no comments, has no/little typing (e.g., no datetime type). It's not good if a human needs to encode data. For configs, I think TOML beats YAML hands down; I think YAML's spot is at encoding data structures that humans need to read/write. I do agree that YAML, the spec, is fairly complicated. But YAML, as used in most projects, by most people, is not, and can be picked up fairly quickly. It is easier to visually read as it removes much of the clutter that would exist in the comparable JSON. It isn't typically necessary to know the entirety of the YAML spec to be useful with YAML, and most of the parts you won't know will get introduced by an obvious-looking sigil, which can be used to figure out what you're dealing with. When I've actually sat with folks struggling with YAML, it's almost always in configuration tools, and it's also always around the templating bits. Ansible, in particular, has a bizarre templating: it happens after YAML parsing, which is not the mental model most people use when approaching it. I've also found that most of the people I've spoken to intertwine YAML and Ansible's templating functions, thinking they're one in the same. I do not think Ansible makes good use of YAML: I would rather write task files in an actual programming language, since they are — at their core — a program. (The tasks do have some metadata attached to them, but the core task itself is a program. A function in some real language can get metadata attached to it in a number of ways, and that would be a better solution.)
- guitarbill 8y agoIt's worth giving Ansible some credit here. Alternatives like Chef, can and do contain arbitrary Ruby logic which can make Chef "cookbooks" horrible to figure out and debug. So while Ansible may not be great, other solutions also have drawbacks, and it isn't quite as easy as do <x>.
- rbankston 8y agoI've worked with both. The simple items are nicer in ansible but when there are a lot of custom roles and functions ansible isn't much better than chef from what I've seen in practice.
- pytester 8y ago
- pavon 8y agoBecause json is poorly suited for config files, and it is very convenient to have config files that closely mirror apis, like kubernetes does. I've seen too many teams who try to use json for config end up developing yet another custom superset of json to allow comments or multiline strings or such. If you are going to use a superset of json might as well use an existing one like yaml or json5. That said I agree with all the criticisms of templating yaml. We have to do the same (with helm and other tools), and I have pushed hard to adopt conventions that we only use flow-style and not block-style to avoid all the white space problems when splicing together chucks of yaml. And on the plus side we get trailing commas and other such niceties which don't exist in json and make it harder template.