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.
*If you like 2, 4 or 8 characters per tab, you can use 2, 4 or 8 spaces. Your editor should be able to change the indentation to your preference if you like.
*Sometimes people do ASCII diagrams, tables, or equations in their comments. These will get messed up with tabs unless everyone who edits them is very disciplined about using spaces and tabs appropriately. (They're not.) When done with spaces they always look consistent.
*You can't type a literal tab in web browser's text box, including Reddit's. Websites can't display true tabs and they don't work properly in copy and paste - not without some Javascript anyway.
*If you like 2, 4 or 8 characters per tab, you can use 2, 4 or 8 spaces. Your editor should be able to change the indentation to your preference if you like.
No. Absolutely not. That would mean changing the whole code because of a formatting preference. If I see any of my colleagues do this, it will warrant a serious proverbial slap.
*Sometimes people do ASCII diagrams, tables, or equations in their comments. These will get messed up with tabs unless everyone who edits them is very disciplined about using spaces and tabs appropriately. (They're not.) When done with spaces they always look consistent.
This is another problem that, yes, solved with spaces. This is not indentation though. This is alignment.
Indentation is what you use for nested code. Alignment is what you do to make the = signs be under each other to be pretty.
*You can't type a literal tab in web browser's text box, including Reddit's. Websites can't display true tabs and they don't work properly in copy and paste - not without some Javascript anyway.
what is this then
Well, without Javascript you can't really make the "Tab" character work nicely. And if you have to sit there and tap Space 12 times for code that's nested 3 levels deep, then you're definitely doing it very wrong.
Any modern IDE should (a) understand the userās intent for encoding tabs or spaces, (b) translate the tab key into that intent, and (c) intelligently auto-indent in accordance with that intent based on the syntactic context.
Nobody should be hammering the space bar a bunch of times to indent multiple levels.
Well obviously, that was a ridicule of the idea of typing code in a web editor that uses the tab key for switching between page elements. Have you read what I was replying to?
Yes, and you made similar remarks (regarding alignment vs. indenting) in other comments in this post, to which I've separately replied. If you like, I can reproduce them here.
I responded here only to address the spacebar thing. And you're not the only person to raise that argument in this post: see here.
I responded here only to address the spacebar thing
which you would know is not a serious suggestion, and just highlighting the ridiculousness of some of the stuff in the post that I replied to. I was writing EXACTLY why it was bad, and now you tell me it is bad.
And you're not the only person to raise that argument in this post
That wasn't my argument, not my post. You're generalizing completely different people who made completely different things, because: Have you read what I was replying to?, the answer should be "No", you didn't read.
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.
You shouldn't align code like that. If you change the length of one of the lines, you need to edit the other line to keep the alignment. This can cause unnecessary merge conflicts.
That's interesting, but there is some nuance here.
The problem with using whitespace in the PEP8 example is that it is in the middle of a statement, which disrupts readability. Alignment of comments following statements is different because the things that are separate are individual units.
For instance, there are clear problems with readability here:
The quick brown fox jumped over the lazy dogs.
She sells seashells by the seashore.
...but not with this:
Goodnight, bears. Goodnight, clocks.
Goodnight, chairs. And goodnight, socks.
In fact, in the latter example, readability is improved by separating the different units. So, too, is readability improved by using whitespace to set comments apart from programming statements.
The problem with using whitespace in the PEP8 example is that it is in the middle of a statement, which disrupts readability.
No, that's not the problem. I already said what the problem was. The problem is that it can cause unnecessary merge conflicts. This is true regardless of whether you're commenting or assigning. Most style choices don't have an impact beyond the immediate readability. This style choice causes further problems with version control.
And among those that are, not all projects have multiple branches that raise the prospect of merge conflicts.
Why should a technical consideration that exists in a sub-subset of projects justify a general-purpose style rule for all projects? Your explanation of āthe problemā does not apply to a vast proportion of Python projects.
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
Not for me. I've done both for a while, and really they both suck at some point. It depends so much on: 1) the type of programming and language, 2) the tools to be used, and 3) the team (if there ever will be one working on that code). Neither is better than the other and "most cases" has little meaning when you start to dig into it. I settled back on tabs for everything I do. I'm ok with spaces if it fits and number has been agreed on, but only when I'm in an IDE/ST3, otherwise annoys the piss outa me if I have to use a stock/simple editor.
Tabs are better than spaces for a number of reasons, but black is the best. It happens to use spaces, but the fact that itās automatic supersedes that.
51
u/zacharypamela Apr 29 '20
Those spaces must've gotten turned around on their way to the Pep 8 club. š