Whitespace

Consistently using whitespace is perhaps the most important code formatting convention that you can adopt in your code. The proper use of whitespace dramatically improves the readability of your code. Consider again the difference between Listing 9.1 and Listing 9.3. It is the exact same code, but Listing 9.1 has all spaces and new lines removed. A guiding principle for using whitespace is that the whitespace should be consistent with the logic of your code. The lines of code inside a function should be indented the same amount, and the lines of code inside a for loop should all be indented the same amount. That way, it is clear which lines are intended to be run in the function or for loop. Listing 9.2 shows how difficult it can be ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.