Carnegie Mellon University
August 20, 2018

Brains on Code

By Josh Quicksall

Can we study the neurocognitive basis for code comprehension? ISR’s Christian Kästner and colleagues to publish research that outlines method for doing precisely that.

Do we learn to program in a similar way to how we learn how to speak a foreign language? That is the question put forward by a group of researchers led by Dr. Janet Siegmund from the University of Passau -  including ISR’s Dr. Christian Kästner - in the paper, “A Look into Programmers’ Heads”, which will be published in an upcoming edition of IEEE Transactions in Software Engineering.

Using functional magnetic resonance imaging (fMRI) of the brain, the team examined the neurocognitive patterns of participants while performing two types of programming tasks. During the first, referred to as comprehension tasks, developers were shown code snippets and asked to identify the programs’ output. In the second, called syntax tasks, the same developers were asked to identify syntax errors in code snippets which, unlike the comprehension tasks, do not require the participant to form an understanding of the program.

The study was conducted on an initial group of 17 participants and replicated with a second group. It showed, during program comprehension, dominant activation of the left hemisphere of the brain in functional areas related to working memory, divided attention, and language comprehension. Additionally, while participants did have to concentrate more with source code that was more complex, which is modulated by the familiarity with the underlying programming language, there was no correlation between programming experience and cognitive effort.

Christian Kästner, Associate Professor in ISR, notes that the significance of these findings lies not in how they dramatically unseat established knowledge, but in how they finally lend some evidence to long-held notions. “From the software engineering perspective, understanding how programmers comprehend source code was elusive or had only been studied very indirectly,” explains Kästner, who helped in designing the code snippet library used during the experiments. “Previously, when we wanted to study comprehension, we needed, for example, participants to verbalize everything they were doing. This fMRI approach gives us much more direct measures and can provide evidence-based answers to questions that have been subject to intense debate, but have been lacking evidence for decades.”

Although these preliminary findings are interesting, Kästner and the team note, what is even more fascinating are the questions that this research method could eventually address, which include: If program comprehension is linked to language comprension, does learning and understanding a programming language require the same struggles and challenges as learning another natural language? If program comprehension dominantly activates the left hemisphere (often referred to as analytical), can we derive better guidelines on how to train students?”

To learn more, visit the team’s project website.