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?

  • Can Git detect if two source files are essentially copies of each others?
  • Git, Nuget, and line endings. Why does it have to be so hard?
  • How can I build an application on a build server by not having all my DLLs in the same repository as the application
  • Versioning with Visual Studio 2010 and HG
  • VS 2015 RC: Git integration crashed
  • Setting up a Git repository for a .NET solution
  • 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.

  • Git Bash bash: open: command not found
  • How can we capture a pull request which is created in bitbucket cloud
  • Add all Pycharm files to git using keyboard
  • How do I clean up the .gitignore file?
  • Change git root folder
  • Why do git branching diagrams not track branches “correctly”?
  • 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.