Part II. Programming Practices

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” —C.A.R. Hoare, The 1980 ACM Turing Award Lecture

The first part of this book covered style guidelines for JavaScript. Style guidelines are aimed at making code look the same regardless of who is working on it. What style guidelines don’t cover is how to solve common problems. That’s where programming practices come in.

Programming practices are another type of code convention. Whereas style guidelines are concerned with the appearance of code, programming practices are concerned with the outcome of the code. You can think of programming practices like recipes—they help developers write their code in such a way that the end result is already known. If you’ve ever used design patterns such as the observer pattern of the model-view-controller (MVC), then you’re already familiar with programming practices. Design patterns are programming practices that solve specific problems related to software organization.

The programming practices in this section cover very small problems. These practices may be considered design patterns by some, but most are simple tips for improving the overall quality of your code.

Both JSLint and JSHint include some warnings for programming practices in addition to stylistic issues. It is highly recommended ...

Get Maintainable JavaScript 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.