Brain Activity When Reading Code #
- Reading computer code activates a different part of the brain than reading natural language.
- The brain region activated when reading code is the "multiple demand network", which is responsible for tasks requiring holding multiple pieces of information in mind.
- The "language regions" of the brain are not activated when reading code.
"Understanding computer code seems to be its own thing. It's not the same as language, and it's not the same as math and logic," says Anna Ivanova, an MIT graduate student and the lead author of the study.
Different Types of Code Reading #
- "Story" Mode: Reading code for the gist of what's happening and what it's about, rather than understanding the technical details.
- "Nuts and Bolts" Mode: Understanding how the code actually works, including the specific functions, variables, and algorithms.
- Inferring Intention: Understanding the purpose of the code, rather than just how it runs.
"I feel like this is akin to asking someone to read a fairytale and to tell you how many times a person crossed a bridge in it, or what they carry in their hand in the end, or where the apple is when all is done. I don’t think this is about understand what is written, it’s about figuring out what that which is written means." - fmbb
The Role of Experience #
- The study suggests that the "unfamiliar problems" zone of the brain may become less active with experience in programming.
- It's unclear whether this zone will still activate when experienced programmers encounter familiar code, or if the brain's response to code changes fundamentally with experience.
- Some programmers argue that code reading becomes more like reading natural language with experience.
- Others believe that code reading remains more akin to spatial reasoning or problem solving.
"I'm approaching 30 years of experience and I do read code like human language. The visualizations I'm using for data structures aren't really much different than visualizing a scene from a book." - Izkata
Implications for Programming Practices #
- The study suggests that code should be written clearly and concisely, even more so than natural language, to minimize the cognitive load on the reader.
- This supports the idea of "clean code" practices, such as using meaningful variable names, writing clear comments, and organizing code logically.
- Many programmers agree that code readability is crucial for both individual and team productivity.
"The mediocre ones write their code for the computer/compiler/interpreter. When it works, they're done. The good ones write their code for human readers to understand, including their future self." - BurningFrog
Comparison with Other Brain Activities #
- Reading code activates similar brain regions as activities like doing math, planning, and problem-solving.
- The brain does not seem to process code in the same way as it processes visual images, sounds, or natural language.
- The study raises questions about how the brain processes formalized representations of information, such as legal documents, musical scores, and mathematical formulas.
Top Quotes #
-
"It's not the same as language, and it's not the same as math and logic." - Anna Ivanova
-
"I feel like this is akin to asking someone to read a fairytale and to tell you how many times a person crossed a bridge in it, or what they carry in their hand in the end, or where the apple is when all is done. I don’t think this is about understand what is written, it’s about figuring out what that which is written means." - fmbb
-
"You can tell because code has no narrator voice in your head when you read it." - blueflow
-
"The mediocre ones write their code for the computer/compiler/interpreter. When it works, they're done. The good ones write their code for human readers to understand, including their future self." - BurningFrog
Key Takeaways #
- Reading computer code is a unique cognitive process.
- It's essential for programmers to write code that is clear, concise, and easy to understand.
- Understanding how the brain processes code can help us to design better programming languages and tools.