3 ms·
> > Avoid trailing whitespace. > This is one of the stupidest things to automate. Unlike indenting, removing trailing whitespace simply produces diffs where it
by thomastjeffery 8y ago
> > Avoid trailing whitespace.
> This is one of the stupidest things to automate. Unlike indenting, removing trailing whitespace simply produces diffs where it doesn’t matter. And does nothing more.
I suppose formatting is a weak point for version control systems, but I think that is all the more reason to get rid of trailing whitespace. The more your code is clean of ambiguous formatting, the less it will change between commits.
- dm3 8y agoExactly! Just separate the commits which fix formatting from the ones that change code.
- Guthur 8y agoIf you got rid of it from the beginning there is no diff. The argument makes no sense.
- kjeetgill 8y agoIn vim it's as simple as :%s/\s* $// (okay, not that simple if you don't spend time in regex or in the shell) and git can hide whitespace only changes in diffs. Just don't check in trailing whitespace. If you need to clean up a whole codebase you can throw in something like find -name * .java | xargs sed -i 's/\s* $//' and just commit that once. Sidebar: How do I print an asterisk and a char without adding in whitespace.
- kbp 8y agoTrailing whitespace also makes jumping to the end of a line or moving back over a newline not take you where you expect, which is annoying when it breaks your flow. It's only ever a mild nuisance (in that scenario or for diffs), but the fact that it's trivial to automate seems to make it a no-brainer to me.