Notes on Programming Style

A programming task involves many decisions. We get to choose names for variables, parameters, and methods. We figure out what the patterns are and whether or not we create methods for them. A good programming style produces code that is easy for others to understand. When you work on a particular project, there may be some elements of programming style that are dictated to you. But the overriding principle of programming style is to write code so that a future reader of the code can easily understand it. The future reader may even be you!

Just as with a paper or a poem, your first draft of a program, even the first version that actually works, is rarely the best. Writing the first version will help you figure out what the right abstractions are, how you can modularize the code, etc. Rewriting for readability is also a normal part of the process.

Some general guidelines follow: