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?
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.
"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."