4 ms·
One thing about yaml that I think conflicts with 'human readable' is the idents mattering. On long files, even with a small number idents, it can be tough to t
by monknomo 3y ago
One thing about yaml that I think conflicts with 'human readable' is the idents mattering. On long files, even with a small number idents, it can be tough to tell whether something is in one section or another. For whatever reason, lining up braces/brackets/parentheses makes it easier for me to tell
- lamontcg 3y agoI'm still baffled at how semantic whitespace 'won' with YAML and Python.
- monknomo 3y agosomething that baffles me is that I find Python's semantic whitespace more comprehensible than YAML's. Haven't figure out why though
- eyelidlessness 3y agoBecause Python only has one semantic meaning for whitespace. YAML’s whitespace is also mixed with other symbols that change what the whitespace means, and it differs further depending on how much whitespace follows the previous indent and precedes the following symbol, if any. Or if the previous line ends with a pipe, then the only semantic meaning is “none of this whitespace matters, so much so that it’s trimmed… but the indentation is preserved after the first line”. I’m probably wrong about some or all of this! It’s been a whole day since I had to write YAML, so the YAML gnomes have rightly reclaimed the part of my brain that was sure I knew what a given bit of whitespace actually means.
- timacles 3y agoPython's use of whitespace is, dare i say, perfect. It makes everything more readable. I've never seen cases where indentation is ambiguous. I think this is because in a programming language indentation happens in a small set of specific situations like `for` loops and such. Either you indent right or you get an error. On the rare occasion the wrong indentation level can assign a variable to the wrong value, but that is a rookie mistake. Whereas in YAML, everything starts out ambiguous. Everything is context sensitive. Indents change the meanings of things in slight, unclear ways. Its a constant source of confusion
- x3haloed 3y agoThe legibility argument. What if I told you that C-style syntax can be formatted to use indentation exactly as you prefer?
- m_eiman 3y agoIn python you split your code into functions when it grows too many indentation levels to be comprehensible. In yaml, you have the whole application logic in one ”function”. Fine for small things, problematic when it grows.
- xigoi 3y agoThe problem with braces is that as a human, you'll still rely on whitespace, and when the whitespace isn't enforced, it can be misleading. if (launch_button_pressed) prepare_missile(); launch_missile();
- Spongman 3y agogcc will give a warning for this. <source>:6:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' 6 | launch_missile(); | ^~~~~~~~~~~~~~ https://godbolt.org/z/cYqhhqz47 https://godbolt.org/z/cYqhhqz47
- lamontcg 3y agoThat should fail a lint check in your CI and your editor/IDE should autoformat that indentation away. You also claim that is a "problem with braces" but you're not using braces and languages like rust no longer allow brace-less single statements like that.
- bobbylarrybobby 3y agoWhich is why you configure your editor to auto format, and then those errors can't exist once you press save.
- x3haloed 3y agoYeah, if I had my druthers, brace-less shorthand syntax like that would never be allowed. I never use it in my own code. Beautify takes care of all questions about what an indent means. C-syntax devs never assume an indent has syntactic meaning. We use it has a helpful hint. We innately understand that it's the braces that matter, and it's really easy to Beautify a file if the original author was sloppy. C-syntax devs read differently. We're not reading a book. We're reading code. And we generally strongly prefer correctness. Braces avoid all unintended bugs related to where the instructions are located on the screen. Pretty is nice. Structure and correctness are better.
- marcosdumay 3y agoIt works much better for Python than for YAML. The details matter, and YAML has all of the worst details. (And if you want proof that the details matter, just look at Haskell, where it works perfectly well.)
- x3haloed 3y agoAmen. My current theory: data science. Data science has become much more prevalent in the last decade, and I suspect data scientists prefer English-like syntax because they're not engineers. Engineers use language like mechanical components. It should be precise, neat, and functional. We're designing machines. I have a feeling that data scientists don't want any of that. They want to use language as a way to describe data transformations in a format that resembles a log rather than functional instructions. Much like SQL.
- efitz 3y agoEncoding meaning in whitespace not only makes it difficult to verify correctness by eye (for nontrivial cases), but also is very fragile. You're lucky if it survives a cut and paste across tools. Almost every tool ever written treats whitespace as formatting, not meaningful content, and many tools therefore assume that "fixing" whitespace will improve readability.
- deleted 3y ago[deleted]