6 ms·
Am I the only one who finds YAML much harder to write than JSON or XML? It's not just the fact that I get the syntax for lists and maps confused all the damn t
by tofflos 6y ago
Am I the only one who finds YAML much harder to write than JSON or XML?
It's not just the fact that I get the syntax for lists and maps confused all the damn time. The worst part is that I'm unable to use the keyboard shortcut for automatically formatting my document!
I love that keyboard shortcut! I hate being without it! I'm certain it represents more than half of my key presses in other languages!
I type a few characters and then I press the code formatting shortcut. That's what I do! That's my workflow!
I don't understand how people who work in whitespace-significant languages can stand being without it! ;-)
(I'm only half-joking - I do find it very frustrating)
- andybak 6y agoMy keyboard shortcut for automatically formatting my documents usually understand the document format or programming language I'm using. If it doesn't then I'm using the wrong editor.
- colejohnson66 6y agoThe problem is that in YAML, white space is significant. How is a formatted supposed to know: key1: value1 key2: value2 ...is supposed to be: key1: value1 key2: value2 ? How is it supposed to know if the first is actually what you meant to write? In grammars that aren’t white space dependent (such as JSON), it’s clear what this means: { "key1": "value1", "key2": "value2" }
- dragonwriter 6y ago{ "key1": values, “key2”: value2 } is valid YAML with the same sematics as it has in JSON; if you have a YAML-aware editor (or editor mode) it will probably format that just as easily as in JSON.
- cageface 6y agoSignificant whitespace seems like a good idea and looks great in small examples but it has some very serious downsides in real use. Being able to reliably reformat hundreds of lines of code with a single keypress is far more valuable than a few saved braces.
- goatlover 6y agoBut it hasn’t hurt Python popularity.
- bobbylarrybobby 6y agoPersonally it’s one of reasons I’m using python less and less and JavaScript more and more. I just can’t stand the white space.
- dragonwriter 6y agoThe difference between Python and YAML is that Python doesn't have a semantically-equivalent, non-indentation-sensitive presentation style. How you choose to view and work with YAML is a choice that doesn't need to have any impact on what you share with others and how they choose to view and work with it. While I'm not usually fond of “you're holding it wrong” arguments, that's pretty much the proper response to complaints about YAML’s indentation sensitivity, since you can work with YAML in a style which isn't indentation sensitive without anyone you share data with seeing anything different.
- cageface 6y agoIt's possible that Python might be more popular than it is without this feature. It's certainly one of the main reasons I avoid it.
- acdha 6y agoPython’s grammar is well defined and has far more validation. YAML has multiple ways to define the same output and since it makes almost anything legal there’s not a way for a tool to disambiguate. For example, if you double-indent something, YAML will just silently assume you wanted a nested data structure but Python will throw an indentation error. That causes issues in many editors when copy-and-pasting. That pattern continues where Python uses indentation to force clarity and consistency but still has syntax which removes ambiguity. A key one is that Python requires quoting data, avoiding all of the common data loss in YAML when people happen to enter data with meaning in YAML (country=no, names with equal signs or colons, etc.), and you have to open and close structures with syntax rather than just indentation. The most analogous Python bug is when a statement immediately after an if, nested def, etc. is one level of indentation than intended. That definitely happens but a fair fraction of the time it’s immediately obvious because it usually fails due to something like a variable not being in scope. YAML consumers are more likely to ignore extra elements so it’s easier to miss things like that for a while unless you have an unusually strict validation stage.
- otterlicious 6y agoYes, in whitespace significant languages whitespace is significant. I could complain that my editor doesn't figure out how to fix all of my braces if I hit a button, after all I got the indentation right and can visually see the structure of my code should be correct no sweat.
- bobbylarrybobby 6y agoThe issue is that in practice it’s quite difficult to reliably get whitespace correct all of the time, whereas braces seem quite easy to get right. If you’ve ever tried cutting and pasting a code block in python you know the pain of having to manually fix whitespace. The same operation in a brace-delimited language has a much smaller chance of going wrong, as the only thing you need to get right is the endpoints of the cut selection.
- wodenokoto 6y agoIf you write { "key1": "value1", "key2": "value2" } without the commas, you're also on your own when it comes to fixing it. You just type [enter] instead of [space] between "value1" and "key2:" in your original example to get correct indentation.
- dragonwriter 6y agoJSON is a subset of YAML, so if you want to write YAML like JSON you can, and you can even automatically convert from JSON style to more idiomatic YAML, or vice-versa, with appropriate tooling.
- ddevault 6y agoCorrection: YAML is a superset of JSON
- ben-schaaf 6y agoTo explain the downvotes: JSON ⊆ YAML implies YAML ⊇ JSON. You're saying the equivalent of "3 > 1 is wrong: 1 < 3".
- doteka 6y agoWhat Drew is saying is absolutely correct though. YAML was specifically designed to be a superset of JSON. Conversely, when JSON was designed, YAML did not exist, so it only became a subset of YAML when the latter was introduced.
- jerf 6y agoThe words subset and superset do not imply any temporal relationship that somebody could get wrong.
- saagarjha 6y agoThe first time I heard that, I thought it was insane. I think it's still pretty insane.
- erik_seaberg 6y agoThat works if all your YAML authors are carefully avoiding any use of the features JSON can’t represent, like multiple documents, non-string map keys, and application-defined type tags.
- jv22222 6y agoNot me, I love YAML. I even write my content like blogs and such in raw YAML!
- pjmlp 6y agoNot alone, my preference goes to XML, and JSON second. So far I have been mostly YAML safe and will try to keep it that way, but it is getting hard when having to deal with k8s.