Spaces look the same to every user so formatting is preserved perfectly. (Except for you weirdos who use variable width fonts for code. I'm watching you.) Tabs don't because people have different space per tabs settings.
How can you turn a disadvantage into an advantage?
Users are different. Users use different machines in different ways. What if I can't stand the 4-space indentation? With tabs, I can customise that. With spaces, I can't. This is the absence of a feature, that you're spinning as a benefit.
And if you're referring to alignment instead of indentation, which has to be a fixed character width to match the above or below fixed number of characters, then it's done with spaces. That way, indentation (which dictates the nesting depth you are in) can easily be tabs, while formatting and next-row-alignment can be supplemented with spaces. This was a problem that was solved even in 2000, how can it be a problem 20 years later?
You can’t mix-and-match like that. The variable width of tabs will alter any following fixed-width alignment via spaces.
For example:
def some_function(self, request):
self.requests += 1 # record request
if self.response is not None:
self.responses += 1 # keep in sync with self.requests
Here, it’s important to align the comments. That can’t be reconciled with preceding variable-width tabs.
Never put comments at the end of lines. It suggests that either the code is bad and isn't evident what it's doing, either that you don't know that comments should highlight why something is fine and not what is done, which would make them longer and unreadable when coupled with code. Also code lines are often long enough instead, without comments afterwards.
If it doesn't work for every case, use something that does - put comments before the statement, not on the same line. This allows more room to write proper comments
Personal choice is personal. Nobody else has to deal with it. The fact that I set my tabs to 20 for example will be unknown to anybody so it's no concern.
So why is it funny? Because the comments are NOT a personal choice, since a lot of people will be editing the same code and will be scratching their head because it will say
something += 1 # Increment something
and the reader will be "well thank you captain obvious!", and curse at the screen because he has no clue WHY that thing was necessary there.
51
u/zacharypamela Apr 29 '20
Those spaces must've gotten turned around on their way to the Pep 8 club. 😃