3 ms·
That's only a problem if you use column alignment, as in your example. But column alignment isn't necessary in coding. It's quite possible - and easy - to write
by Stratoscope 11y ago
That's only a problem if you use column alignment, as in your example. But column alignment isn't necessary in coding. It's quite possible - and easy - to write perfectly readable and maintainable code using indentation only and no column alignment.
Defining my terms a bit: By "indentation" I mean whitespace at the beginning of a line without any dependency on character widths. Extra whitespace in the middle of a line is "column alignment", and so is whitespace at the beginning of a line when the number of spaces depends not only on an indentation level, but also on matching other text in the previous line.
In your example, the "if" line uses indentation only, but the line beginning with "f == g" uses a mix of indentation (to match the indentation of the "if" line) and column alignment (the extra spaces to line the "f" up with the "a" above).
One good way to think about it is to imagine (or actually test) what the code would look like in a proportional font. If it still looks properly formatted, you're probably just using indentation. If the formatting gets messed up (e.g. the "a" and "f" no longer line up), you're using column alignment.
Avoiding column alignment has many benefits. If you ban it from your code, so many formatting issues go away completely.
I've written about this on HN a few times, so I'll leave the details to one of my previous posts:
https://news.ycombinator.com/item?id=10206860 https://news.ycombinator.com/item?id=10206860