O'Reilly logo

Reliable JavaScript: How to Code Safely in the World's Most Dangerous Language by Seth Richards, Lawrence Spencer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 4 Reviewing the Benefits of Patterns

WHAT’S IN THIS CHAPTER?            

  • Exploring how a simple pattern has brought us increasingly clear and reliable code
  • Making your code simpler and clearer
  • Looking ahead

CASE STUDY

World chess champion Magnus Carlsen was referring to chess, but he could have been talking about programming when he said: “[In] general good players use more long-term memory than short-term memory during a chess game. You use past experiences. It is the intuition that is largely based on the past experiences. So it is your experience that gives you a different impression of the new situations before you, and then you have to consider what impression you can use. You must be able to continuously make up your mind about which past experience can be used.” (http://www.worldchesschampionship2013.com/2013/11/secret-of-magnus-carlsens-chess.html)

Good chess players strike with flashes of tactical brilliance at the chessboard, and good programmers can spin beautiful algorithms at the keyboard, but the best ones also draw on patterns learned from experience and “continuously make up their minds about which can be used.” A developer who draws on wisdom and experience from the past is likely to solve problems more economically and cleanly than one who must invent everything himself.

Patterns can range in scale from little idioms of the language (++i) up to the structure of the system itself (n-tier architecture). The pattern of looping through an array is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required