A Blog by Jonathan Low

 

Apr 4, 2021

What Human Brains Are Doing When They Read Code

Left brain/right brain analysis is too simplistic, but it provides clues as to how and why the brain interprets and creates computer code.

This is knowledge will be increasingly useful as coding becomes an even more essential skill. JL

 Rina Caballar reports in IEEE Spectrum:

Despite the structural similarities between programming languages and natural languages, the researchers found that the brain does not engage the language system—it activates the multiple demand system, which tends to be engaged in cognitively challenging tasks such as solving math problems or logical reasoning. (It) stores code-relevant information, including common coding concepts and knowledge specific to a programming language. How much each individual relies on the left brain to read code is associated with how much they rely on the left brain to do linguistic tasks.”

Coding is becoming an increasingly vital skill. As more people learn how to code, neuroscientists are beginning to unlock the mystery behind what happens in people’s brains when they “think in code.”

“Computer programming is not an old skill, so we don’t have an innate module in the brain that does the processing for us,” says Anna Ivanova, a graduate student at MIT’s Department of Brain and Cognitive Sciences. “That means we have to use some of our existing neural systems to process code.”

Ivanova and her colleagues studied two brain systems that might be good candidates for processing code: The multiple demand system—which tends to be engaged in cognitively challenging tasks such as solving math problems or logical reasoning—and the language system. Despite the structural similarities between programming languages and natural languages, the researchers found that the brain does not engage the language system—it activates the multiple demand system.

The result was consistent regardless of programming language (the study focused on Python and ScratchJr, a visual programming language for children), problem type (math versus string manipulation), and code elements (sequential statements, if statements, and for loops). The study also found that the multiple demand system likely stores representations of code-relevant information, including common coding concepts (such as loops) and knowledge specific to a programming language (such as the syntax of a for loop in Java versus Python).

Yet coding and math and logic don’t rely on entirely the same brain mechanisms. “The multiple demand system includes regions in the left and right hemispheres,” Ivanova says. “For math and logic, we usually see more activity in the left hemisphere. For code, it activated the multiple demand system in both hemispheres, so the activation pattern is different from what we see for math and logic.”

Results from MIT’s research tie in with a similar study from Johns Hopkins University (JHU), where researchers found that the neural mechanisms for reading and understanding code overlap with logic, and to a lesser degree with math. But the JHU study indicates a stronger reliance on the left side of the brain’s multiple demand system. (Both the MIT and JHU studies were published in a recent issue of the journal eLife.) 

“When reading code, we may prefer to use the left version of this network,” says Yun-Fei Liu, a graduate student at JHU’s Neuroplasticity and Development Lab and lead author of the study. However, there might be an individual difference on which side to use, which Liu likens to handedness.

“Most people use their right hand to write, while some people use their left, and fewer people can use both hands. That might also be true for reading code,” Liu says. “Most people use the left logical reasoning system, and some use a bit of the right, but maybe some people use both. How much each individual relies on the left brain to read code is associated with how much they rely on the left brain to do linguistic tasks.” This suggests that language may still play a role in understanding code even if the brain doesn’t engage its language network.

While the MIT study didn’t identify any specialized region in the multiple demand system dedicated to interpreting code, Ivanova notes it’s possible to develop such a region as proficiency in programming grows. “Maybe if you’re extremely good, you will have some dedicated chunk of brain tissue for code. But you don’t need it to be a good programmer,” she says.

Both studies come with the limitation of having a small number of participants and using short code snippets. “These aren’t huge programming tasks where a lot of domain knowledge is involved—and you would implement complex business logic,” says Barbara Weber, a professor at the University of St. Gallen in Switzerland who also conducted a comprehensive review of studies on brain activity measurement in software engineering that was published in a recent issue of The Journal of Systems and Software. “We don’t know if the brain behaves exactly the same with a large code base having hundreds of lines of code.” Further studies may also be needed to determine if the brain behaves differently based on the type of coding task (front-end versus back-end or writing versus debugging code) and the programmer’s skill level.

According to Ivanova, the benefits of studying the cognitive and neural foundations of coding are twofold. “We’ll have a more scientific basis to inform our understanding of the most effective way to teach programming,” she says. “And we can leverage the broader domain of cognitive science to figure out how we can design programming languages that are adapted to the specifics of the human brain.”

0 comments:

Post a Comment