YML and Python... the great whitespace debate

I hate YML and Python.

Well, that may be a bit stronger than I actually feel. But, they both make a cardinal mistake; a belief that indentation is a reasonable way to convey structure.

This might sound like a weird argument. But, here is a perfect example:

I was writing some Python code the other night, using various free learning resources to fill in the gaps as I learned Python. As an existing programmer (or as any learner would be encouraged) I was also modifying the code I was pulling in.

For a while the edits worked fine. Presumably I was doing more deleting existing lines, or modifying lines.

Then, out of nowhere... CRASH. My code stops compiling. I get a cryptic error about inconsistent indentation. I go back to my code. Everything is nice and uniformly indented. Except, it isn't. Lines I added and manually indented used TAB indentation. And the examples I copied used spaces. It didn't matter that visually they looked identical and that there was virtually no way to distinguish one from the other.

Stupid.

Braces and brackets and other constructs work in other languages. They don't detract much from brevity, and while uniformly indented code IS easier to read. You can have uniformly indented code which also uses braces and have it remain just as readable, while discarding the explicit requirement that every piece of white space uses the same character codes to achieve the effect.

Now, I fully understand that code can get downright messy if no indentation or inconsistent indentation is used. But, most IDEs give you automatic indentation for free. Most people who work in teams are subject to policies they must adhere to regarding coding standards. And, there are often reasons to permit breaking of styling rules.

One such reason for breaking styling rules? Minification. You try and minify a YML file. I dare you!

And so we have the next culprit; YML. At least Python will let me do my thing as long as I'm consistent. It isn't even nearly OK. But, YML is strictly "2 lines of indentation per level. PERIOD."

This is both better and worse than Python. It is better because it is SO strict that linters and other tools can pick this up easily enough. But worse because it is once again a silly, arbitrary requirement.

I know that the tab vs space argument is ancient. But, tab is purpose built for indentation purposes and it is a single keystroke per indentation. Spaces are typically 2+ making it more key strokes.

But, I don't really care which is better. What I do care about is that both have seemingly made choices with horrible trade-offs.

Python would actually be better off with 100% strict rules like YML. Code is code. I don't typically need to serialize it. But, if the language at least enforces exactly one indentation approach, it can be caught before compile time.

YML is just dumb. I don't know how it was originally envisioned. But, today it is largely used like JSON. Only... you know, you can't minify it in any way shape or form. And, if you indent JSON properly, it is no more or less readable.

I know this is a dumb argument. But I can't sleep and I don't care.

Comments

Popular Posts