Format Code Like Prose

Writing code is also writing for other people. We use many conventions in written communication to help with readability. Ever sit down to read someone else’s code and it’s giant wall of procedural statements for 100 lines straight? Imagine reading a paragraph that goes on for 100 lines.

I like to format code like prose. Statements in a long function that complete an idea should be grouped together visually—think of it as a paragraph and add some newlines for the reader to take a breath. Write linearly so it’s easy to read from beginning to end (you don’t read a book by jumping around back and forth between pages). Organize hierarchically from most general to specific (e.g. the last line is generally expected to be the return value so use early returns for edge cases rather than the main case).