a string of computer code overlaid on top of a brain

Credit: Johns Hopkins Magazine

Inside programmers' brains

A Johns Hopkins study offers clues to which parts of the brain are involved in coding

Inside a whirring fMRI machine, a computer programming challenge flashed across a screen suspended above a Johns Hopkins graduate student. Her eyes scanned the passage of code attempting to figure out a riddle of sorts: If these words, numbers, and symbols were typed into a computer, how would the device respond?

Nearby, another graduate student worked to decipher another puzzle: What part of the brain oversees computer programming? Systems such as JavaScript are described as languages, suggesting the parts of the brain that control language might also control coding. On the other hand, most of the first computer programmers were mathematicians or engineers, indicating those with a knack for math also excel at coding. Or could there be a different part of the brain that oversees this task?

The answer could have broad implications for how and when coding, an increasingly important skill, is taught. Yun-Fei Liu, the doctoral candidate in Johns Hopkins University's Neuroplasticity and Development Lab who devised the experiment, believes he is among the first scientists to attempt to answer this question. While humans have been speaking, writing, and solving math problems for millennia, Ada Lovelace sketched out the first computer program in the 1840s. Modern coding dates back only as far as the 1950s.

"If we can find the neural basis of programming and see which other cognitive functions share their neural basis, it provides a hint to what skills are needed to learn to code."
Yun-Fei Liu
JHU Neuroplasticity and Development Lab

"People have posed different ideas about what is relevant when you want to be a good programmer," Liu says. "If we can find the neural basis of programming and see which other cognitive functions share their neural basis, it provides a hint to what skills are needed to learn to code."

In Liu's study, which was published late last year in the journal eLife, people with at least five years of programming experience were given a series of coding problems to solve in Python while the fMRI mapped the areas of their brains that were most active. The participants' brains were also mapped while they looked at code that had been scrambled. Liu then compared the brain activity of the participants when they were looking at the nonsense and when they were parsing real code. He wanted to see which brain regions were active when a person was thinking through a programming challenge, not just looking at words and symbols on a screen. 

Participants also completed several other tasks involving language, math, and logic, as well as executive function—the essential thought processes that include concentration, self-control, and emotional regulation. This enabled researchers to map the areas of the brain the participants used for these tasks and compare them to the regions active in coding.

So where is the brain's computer science department located? Liu found that areas that involved logical thinking were most active when participants pondered code. For example, the lateral prefrontal cortex, which handles reasoning and planning, lit up during the study's activities. (This is the same part of the brain you would rely on to, say, raise your left hand if you see a circle and right hand if you see a square.) The left side of the brain, which is associated with language, was also more active than the right during the tasks, Liu found. Those participants who more intensely favored their left brains during the language activities also more intensely favored their left brains in coding activities, he says.  

"Language and coding seem to follow each other to the same hemisphere," says Marina Bedny, an associate professor in Psychological and Brain Sciences and senior author of the study. "If my language responses are more highly left hemisphere, then my coding responses will be more highly left hemisphere."

While the study had a relatively small sample size—15 participants—it was published alongside a separate study from researchers at the Massachusetts Institute of Technology that also used fMRIs to analyze brain processes involved in coding. That study used slightly different methodology but came to similar conclusions. 

Next, Bedny and Liu would like to study what happens to the brain when a person learns to code. How does the brain change over time? Do logical reasoning skills also improve? Would we use different parts of our brain if we learned the skill in elementary or middle school?

"We still don't know the best time to learn to code," Liu says. "Right now, many people don't learn to code until they are adults. But would it be easier to learn during the teen years or childhood? Given how important coding is to modern society, we should know if we are waiting too long."