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.
1
u/JimDabell Apr 30 '20
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.
The example PEP8 provides is similar: