4 ms·
something that baffles me is that I find Python's semantic whitespace more comprehensible than YAML's. Haven't figure out why though
by monknomo 3y ago
something 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.