Math or language? —

How does the brain interpret computer languages?

Neuroscientists detect a distinct brain network that grows stronger with practice.

Image of a pillar covered in lit ones and zeroes.

In the US, a 2016 Gallup poll found that the majority of schools want to start teaching code, with 66 percent of K-12 school principals thinking that computer science learning should be incorporated into other subjects. Most countries in Europe have added coding classes and computer science to their school curricula, with France and Spain introducing theirs in 2015. This new generation of coders is expected to boost the worldwide developer population from 23.9 million in 2019 to 28.7 million in 2024.

Despite all this effort, there’s still some confusion on how to teach coding. Is it more like a language, or more like math? Some new research may have settled this question by watching the brain’s activity while subjects read Python code.

Two schools on schooling

Right now, there are two schools of thought. The prevailing one is that coding is a type of language, with its own grammar rules and syntax that must be followed. After all, they’re called coding languages for a reason, right? This idea even has its own snazzy acronym: Coding as Another Language, or CAL.

Others think that it’s a bit like learning the logic found in math; formulas and algorithms to create output from input. There’s even a free online course to teach you both coding and math at the same time.

Which approach is more effective? The debate has been around since coding was first taught in schools, but it looks like the language argument is now winning. Laws in Texas, Oklahoma, and Georgia allow high school students to take computer science to fulfill their foreign language credits (the 2013 Texas law says this applies if the student has already taken a foreign language class and appears unlikely to advance).

The debate holds a special interest for neuroscientists; since computer programming has only been around for a few decades, the brain has not evolved any special region to handle it. It must be repurposing a region of the brain normally used for something else.

So late last year, neuroscientists in MIT tried to see what parts of the brain people use when dealing with computer programming. “The ability to interpret computer code is a remarkable cognitive skill that bears parallels to diverse cognitive domains, including general executive functions, math, logic, and language,” they wrote.

Since coding can be learned as an adult, they figured it must rely on some pre-existing cognitive system in our brains. Two brain systems seemed like likely candidates: either the brain’s language system, or the system that tackles complex cognitive tasks such as solving math problems or a crossword. The latter is known as the "multiple demand network."

Coding on the brain

In their experiment, researchers asked participants already proficient at coding to lie in an fMRI machine to measure their brain activity. They were then asked to read a coding problem and asked to predict the output.

The two coding languages used in the study are known for their "readability"—Python and ScratchJr. The latter was specifically developed for children and is symbol-based so that children who have not yet learned to read can still use it.

The main task involved giving participants a person’s height and weight and asking them to calculate a person’s BMI. This problem was either presented as Python-style code or as a normal sentence. The same method was done for ScratchJr, but participants were asked to track the position of a kitten as it walked and jumped.

Control tasks involved memorizing a sequence of squares on a grid (to activate participants’ multiple demand system) and reading one normal and one nonsense sentence (to activate their language system).

Their results showed that the language part of the brain responded weakly when reading code (the paper’s authors think this might be because there was no speaking/listening involved). Instead, these tasks were mostly handled by the multiple demand network.

The multiple demand network is spread across the frontal and parietal (top) lobes of our brain, and it's responsible for intense mental tasks—the parts of our lives that make us think hard. The network can be roughly split between the left part (responsible for logic) and the right (more suited to abstract thinking). The MIT researchers found that reading Python code appears to activate both the left and right sides of the multiple demand network, and ScratchJr activated the right side slightly more than the left.

“We found that the language system does not respond consistently during code comprehension in spite of numerous similarities between code and natural languages,” they write.

Interestingly, code-solving activated parts of the multiple-demand network that are not activated when solving math problems. So the brain doesn’t tackle it as language or logic—it appears to be its own thing.

The distinct process involved in interpreting computer code was backed up by an experiment done by Japanese neuroscientists last year. This work showed snippets of code to novice, experienced, and expert programmers while they lay in an fMRI. The participants were asked to categorize them into one of four types of algorithms. As expected, the programmers with higher skills were better at categorizing the snippets. But the researchers also found that activity in brain regions associated with natural language processing, episodic memory retrieval, and attention control also strengthened with the skill level of the programmer.

So while coding may not be as similar to languages as we had thought, it looks like both benefit from starting young.

eLife, 2020. DOI: 10.7554/eLife.58906  (About DOIs).

Fintan is a freelance science journalist based in Hamburg, Germany. He has also written for The Irish Times, Horizon Magazine, and SciDev.net and covers European science policy, biology, health and bioethics.

Channel Ars Technica