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