Chapter 1. How to read complex code

 

Chapter 4 from The Programmer's Brain by Felienne Hermans

This chapter covers:

  • Analyzing what happens when your working memory is overloaded by very complex code
  • Comparing and contrasting two different types of working memory overload when programming
  • Refactoring code for readability to compensate for an overloaded working memory
  • Creating a state table and a dependency graph to support your working memory when reading complex code

Chapter 1 introduced the different ways in which code can be confusing. We’ve seen that confusion can be caused by a lack of information, which must be acquired and stored in your short-term memory, or by a lack of knowledge, which requires storing information in your long-term memory. This chapter covers the third source of confusion: a lack of processing power in the brain.

Sometimes the code you are reading is just too complex for you to fully understand. Because reading code is not an activity that most programmers practice often, you might find yourself lacking strategies to deal with reading code that you do not understand. Common techniques include “read it again” and “give up,” neither of which is that helpful.

4.1       Reading complex code

4.1.1   What’s the difference between working memory and short-term memory?

4.2        What happens in the working memory when you read code?

4.2.1   Intrinsic cognitive load when reading code

4.2.2   Extraneous cognitive load

4.3       Refactoring code to reduce cognitive load

4.3.1   Inlining code

4.3.2   Replacing unfamiliar language constructs

4.3.3   You want to consider cognitive load when writing code, too

4.4       Marking dependencies

4.5       Using a state table

4.5.1   Combining state tables and dependency graphs

4.6       Summary