Why is indentation in empty lines bad?

烂漫一生 提交于 2019-12-02 21:48:10

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!