Which is preferred ("." indicating whitespace)?
A)
def foo():
x = 1
y = 2
....
if True:
bar()
B)
def foo():
x = 1
y = 2
if True:
bar()
My intuition would be B (that's also what vim does for me), but I see people using A) all the time. Is it just because most of the editors out there are broken?
That empty line belongs to
foo()
, so I would considerA
to be the most natural. But I guess it's just a matter of opinion.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 rungit 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.I wouldn't necessarily call the first example "broken", because I know some people hate it when the cursor "jumps back" when moving the cursor up or down in code. E.g. Visual Studio (at least 2008) automatically prevents this from happening without using any whitespace characters on those lines.
TextMate breaks block collapsing if you use B, and I prefer A anyway since it's more "logical".
If you use A, you could copy paste your block in python shell, B will get unexpected indentation error.
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.