Which is preferred (\".\" indicating whitespace)?
A)
def foo():
x = 1
y = 2
....
if True:
bar()
B)
Emacs does B) for me, but I really don't think it matters. A) means that you can add in a line at the correct indentation without any tabbing.
That empty line belongs to foo()
, so I would consider A
to be the most natural. But I guess it's just a matter of opinion.
My experience in open-source development is that one should never leave whitespace inside blank lines. Also one should never leave trailing white-space.
It's a matter of coding etiquette.
vi
implicitly discourages the behaviour in A because the {
/}
navigations no longer work as expected. git
explicitly discourages it by highlighting it in red when you run git diff
. I would also argue that if a line contains spaces it is not a blank line.
For that reason I strongly prefer B. There is nothing worse than expecting to skip six or so lines up with the {
motion and ending up at the top of a class def.
If you use A, you could copy paste your block in python shell, B will get unexpected indentation error.
Adding proper indentation to blank lines (style A in the question) vastly improves code readability with display whitespace enabled because it makes it easier to see whether code after a blank line is part of the same indentation block or not.
For a language like Python, where there is no end statement or close bracket, I'm surprised this is not part of PEP. Editing Python with display whitespace on is strongly recommended, to avoid both trailing whitespace and mixed indentation.
Compare reading the following:
A)
def foo():
....x = 1
....y = 2
....
....if True:
........bar()
B)
def foo():
....x = 1
....y = 2
....if True:
........bar()
In A, it is far clearer that the last two lines are part of foo
. This is even more useful at higher indentation levels.