Chapter 4. Anti-Patterns
As engineers, we may run into situations when we are on a deadline to deliver a solution or where code gets included as a series of patches without a code review. The code in such cases may not always be well thought out and may propagate what we call anti-patterns. This chapter describes what anti-patterns are and why it is essential to understand and identify them. We also look at some typical anti-patterns in JavaScript.
What Are Anti-Patterns?
If a pattern represents a best practice, an anti-pattern represents the lesson learned when a proposed pattern goes wrong. Inspired by the GoF’s book Design Patterns, Andrew Koenig first coined the term anti-pattern in 1995 in his article in the Journal of Object-Oriented Programming, Volume 8. He described anti-patterns as:
An antipattern is just like a pattern, except that instead of a solution, it gives something that looks superficially like a solution but isn’t one.
He presented two notions of anti-patterns. Anti-patterns:
-
Describe a bad solution to a particular problem that resulted in an unfavorable situation occurring
-
Describe how to get out of the said situation and go to a good solution
On this topic, Alexander writes about the difficulties in achieving a good balance between good design structure and good context:
These notes are about the process of design; the process of inventing physical things which display a new physical order, organization, form, in response to function. … Every design ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access