Every FOSS project I know has rules against trailing whitespace in code. But I think it\'s very natural to continue the current indentation on the next line:
int
I think it boils down to "no redundant hidden surprise bytes in your code plz".
As @sarnold points out, redundant surprise bytes make patching and diffs unnecessarily messy.
This can also be rude to vi users who are accustomed to using paragraph navigation to jump around through code. Sometimes I do this when vi and it's quite surprising when I skip several functions because invisible characters said this is actually part of the previous paragraph.
It is probably because merging patches with useless whitespace is harder than it should be.
diff(1)
and patch(1)
treat spaces and tabs as important content. (Ask any Makefile
or .py
source file -- they are important!) And if your "blank line" has four spaces on it, and my "blank line" has eight spaces on it, any attempt to share patches between us will fail for very trivial reasons.
Granted, if you wholesale change the indentation of a block of code, you'll have to go to some work to make patches apply anyway. But trying to track down merge failures on lines that look blank is painful. (I've wasted too much of my life doing just that. Yes, vim
listchars
can help, but reading code with listchars
on all the time is also annoying.)
So people standardize on no trailing whitespace. It might not really make sense to worry about a dozen lost bytes here or there from a storage standpoint, but it really makes merging patches easier. We could probably just as well standardize on adding trailing whitespace, exactly as you have suggested, and be just as happy, but we might as well standardize on the approach that is as parsimonious as possible.