Wednesday, May 13, 2009

Code formatting is something I don't mess with too much. I'm not going to make gratuitous formatting changes in code. It makes extra entries in the source control. And the biggest problem with reformatting code is that it gratuitously makes tracking differences between branches harder.

However, even if I'm not going to mess with it, there are matters of formatting that I don't like.

Lots of people indent with tabs. Plus, they generally use 4-space tabs. I use emacs, which defaults to 8-space tabs. So tab-indented code generally looks like crap to me. I could do (setq tab-width 4) if it really bugged me, but it usually doesn't. I always indent with spaces.

Some people put trailing whitespace on lines, which I find annoying. I think lots of editors put indenting whitespace on blank lines. But some people put trailing whitespace on non-blank lines.

This one guy always put a space after an open parenthesis, and a space before a close parenthesis, which I think looks bad.

I also don't like source files that don't end with a newline. I don't know how to get vi to save a text file that doesn't end with a newline, but it seems to me that IDEs and Microsoft Windows based editors make the end of the file ambiguous, because there are files that either end with no newline, or end with multiple blank lines. Ending with multiple blank lines is annoying the way trailing whitespace on lines is annoying. However, files that don't end with a newline make unified diffs look bad when the last line is involved.

No comments:

Post a Comment