Making code more readable sometimes means knowing where to put nothing.

Programming has strict rules about the meaning of the code. And compilers don’t care how easy the code is to understand. It either follows the rules or not.

But as humans, we do care. Because if code is hard to read, then it’s hard to understand. And that increases the chances that mistakes will be made resulting in bugs. That’s assuming the project can be finished at all.

I’ve already explained many aspects of making your code more understandable from how to name variables, methods, and classes, to the proper use of comments. And there’s the whole subject of design patterns that can help structure your code into common designs that have evolved and been proven to work well.

This episode is about whitespace which includes spaces, tabs, and new lines. If you were to print your source code on plain white paper, then whitespace is anything that results in nothing being printed.

For example, take the placement of opening and closing curly braces. Some people prefer to put the opening curly brace at the end of the line that starts the block. An if statement would then have the if keyword followed by the expression in parenthesis and then an opening curly brace all on the same line. I think this style is liked by some because a lot of books take this approach. But if you think about it, a book needs to save space and having a curly brace on a line all by itself wastes a lot of space. When programming though, vertical space is usually not as much of a problem. And especially these days with the size of computer monitors as big as they are.

I like my curly braces to line up. Not only does this help me to read the blocks of code better but it’s consistent. Make sure to listen to the full episode for more explanation.