Better Code through Chunking!

I'm on a plane en route to Perth, and have just finished reading an article in Scientific American called "The Expert Mind". Essentially it discusses a theory employed by chess masters called Chunking, where instead of seeing a board as being made up of a collection of individual pieces (as I see a chess board while I play), they see it as one or two chunks of information, such as:

"the isolated queen's-pawn position from the Nimzo-Indian Defense" and "minus the dark-squared bishops" [1]

Something immediately clicked with me as a read this! The article is a great read, and goes into why chess masters are able to make game winning, flawless moves quickly and accurately employing the chunking theory/approach.

For developers, this is critical, as many bugs and defects are encapsulated in code patterns. Much like the chess chunks (I love the names they give board configurations..."fianchettoed bishop in the castled kingside"!!!) provide immediate and accurate patterns, so the same occurs in code.

So what if developers were to spend time training themselves into the patterns of code that provide bug-free solutions. True, they could only learn a chunk at a time, and while each chunk may produce bug free code, the combination of chunks could result in bugs. But, again, looking at chess (I'm really loving this analogy, "blockaded king's-Indian-style pawn chain"!!), it's not about the chess board at a point in time, it's about the whole game, again, much like a program is more than one section of code or procedure.

So what now, instead, developers learnt code chunks, and the chains of code chunks that led to bug-free code to achieve a particular objective, such as performing a database update (much like all the chess chunks win a game without error...what I mean by this is even if the chess master loses a piece, it is not unexpected, like a bug in code). Again, this requires a greater deal of discipline and training for developers (something that on the whole is lacking in our industry), but for those who realize the financial value of lowering the number of bugs in code from time zero, this could be a real boon!

Wow, I'm going to start experimenting with this concept, see if I can start creating my own book of code moves much like the chess masters do, that will result in defect free code! I'll even give the chunks cool names like "Heraldo by the cherry bush looping infinitely harasaki"!

[1] Philip E. Ross, The Expert Mind, Scientific American, Vol. 295, Num. 2, August 2006

Comments (6)
  1. Anonymous says:

    Isn’t this kind of like "Design Patterns"?

  2. davidlem says:

    Not really, design patterns are about applying a template approach to a problem. My concept is about learning code patterns (actual blocks of syntax) and then tweaking them to accomodate for different problems. Almost like code snippets but inside your head!

  3. JosephCooney says:

    these "chunks" sound a lot like GoF design patterns. Chess players obviously have a shared vocabulary for describing positions on the board, similar to what design patterns give developers? "singleton flyweight factory decorator" probably sounds equally amusing to chess players.

  4. davidlem says:

    The idea behind chunking though, is not to apply a pattern approach to solving a problem, it’s to train yourself to act in a predictable way when presented with a problem. It’s about subconsciously training developers to write bug free code from their fingers to the IDE. Patters are great for solving a problem using a consistent approach, but I can still code a bug while following a pattern.

  5. I caught up with Daz and Mitch yesterday for a quick coffee and chin wag while both Readifians were illin’…

Comments are closed.

Skip to main content