This Is Your Brain on Code
Reading time: 2 minutes
Programmers tend to have strong opinions about what makes code easier or harder to understand. Until recently, though, those opinions have been based on self-analysis and received wisdom, i.e., on programmers thinking about what they themselves do, and (more often) on what the rest of the herd is saying.
A new wave of studies made possible by plummeting hardware costs is going to change that. Some of these studies use eye tracking to discover how programmers actually read code. As shown by the two videos below (taken from Mike Hansen's work at Indiana University), novice and expert programmers read code very differently, but neither group reads left-to-right and top-to-bottom.
Hansen and his colleagues reported that, "...experience increases performance in most cases, but may hurt performance significantly when underlying assumptions about related code statements are violated." This doesn't just confirm the importance of using consistent style; it is a first step toward being able to quantify the costs of inconsistency, and to compare the differences (if any) between different styles.
Other groups have taken this work even further. Last year, Benjamin Floyd and colleagues published a report based on functional magnetic resonance imaging (fMRI) studies of the activity in programmers' brains while they were reading and writing code. Their conclusions are worth quoting directly:
“In a controlled experiment involving 29 participants, we examine code comprehension, code review and prose review using functional magnetic resonance imaging. We find that the neural representations of programming languages vs. natural languages are distinct. We can classify which task a participant is undertaking based solely on brain activity... Further, we find that the same set of brain regions distinguish between code and prose (near-perfect correlation). Finally, we find that task distinctions are modulated by expertise, such that greater skill predicts a less differentiated neural representation indicating that more skilled participants treat code and prose more similarly at a neural activation level.”
In simpler terms, they discovered that different people process code and natural language in the same way, but that every individual processes code and natural language differently, and that the more experienced a programmer is, the more closely their brains treat code and natural language.
This may not seem to have a lot to do with getting the next revision of your application out the door, but we believe it's a sign of things to come. Every business routinely uses analytics to find out how customers are using its website (at least, every business that wants to stay in business), and every serious development team tracks time, bugs, test coverage, and so on. It's a natural step to apply that same mindset to the act of programming---to gather data on what people actually do when they're reading, writing, and testing software, and to use it to help them get better. Today's professional athletes learn a lot about anatomy and physiology in order to be the best they can be; one day, perhaps, it will be equally routine for programmers to learn how their brains work so that they can excel too.