Why is indentation in empty lines bad?

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 main()
....int a = 42;
....return a;

But git for instance throws warnings anyway. So my question is: Why are those tabs inside the current indentation bad?

  • Embedded linux/android kernel development workflow
  • Is there a program (or sed script) that will remove a function from a C file?
  • C++11 settings in Eclipse Indexer conflict with git
  • How do I use VisualStudio git extensions to access remote repository using password access?
  • Decoding Git index file using C#
  • Git breaks my program?
  • I’m not looking for answers like “It’s always done this way”. Let’s assume indentation is done consistently in the whole project in question.

  • how to control ownership of files auto-pushed to a git target repo by commit hooks?
  • Github for mac diff options
  • How do I enable auto-complete for a git-flow alias?
  • Git push error ' master -> master (branch is currently checked out)'
  • Github, git, how to submit changes to an upstream repo
  • .git/info/exclude replacement for git submodule?
  • 3 Solutions collect form web for “Why is indentation in empty lines bad?”

    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.

    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.

    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.

    Git Baby is a git and github fan, let's start git clone.