DEV Community

Cover image for Scientists Scanned Programmers' Brains Reading Python. The Language Centres Barely Noticed.
Spartan Rich
Spartan Rich

Posted on

Scientists Scanned Programmers' Brains Reading Python. The Language Centres Barely Noticed.

Python first appeared in 1991. Your brain has been evolving for a few hundred thousand years. It had no time to grow a part for reading code.

So when you stare at a nested loop and work out what it prints, what is your head actually using?

For a while the popular answer was "the language centres, obviously". Code has vocabulary. It has grammar. We even call them programming languages. Then a few labs put programmers inside MRI scanners and checked.

The first scan said: language

In 2014, Janet Siegmund and colleagues ran one of the first fMRI studies of programmers (ICSE 2014). Seventeen computer science and maths students read short Java snippets and worked out what each one would output. As a control, they also scanned the same kind of code just to spot injected syntax errors.

Subtract one from the other and you get the "understanding" part. It lit up five areas in the left hemisphere, Brodmann areas 6, 21, 40, 44 and 47. Area 44 sits in Broca's region, which is tied to building sentence structure. The authors' conclusion was simple: program comprehension looks closely related to language comprehension.

It was a great headline. It was also one small study with one kind of control task.

Then MIT asked a sharper question

In 2020, Anna Ivanova, Evelina Fedorenko and a team from MIT and Tufts tried it differently (eLife, 2020). Instead of guessing which blobs were "language", they first mapped each person's own language network with a standard localiser task. Then they showed them code.

One group read Python. Another read ScratchJr, a block-based language built for five-year-olds. In both, people had to predict what the code would do.

The language regions barely reacted. As MIT News put it, the team saw "little to no response to code in the language regions of the brain."

What did fire was the multiple demand network, a spread of frontal and parietal regions that handles anything that makes you hold several things in mind at once. Ivanova's description: "It does pretty much anything that's cognitively challenging, that makes you think hard."

Code didn't look exactly like maths either. It recruited both left and right sides of that network, while maths and logic lean left. "Understanding computer code seems to be its own thing," Ivanova said. "It's not the same as language, and it's not the same as math and logic."

A vintage textbook drawing of a brain with a warm orange network lit across the frontal and parietal lobes and a pale blue language strip barely lit

Same issue, different lab, closer to logic

In the very same issue of eLife, Yun-Fei Liu, Judy Kim, Colin Wilson and Marina Bedny at Johns Hopkins published a companion study (eLife, 2020). Their volunteers were experts, with an average of 11 years of programming.

Reading Python recruited a left-sided fronto-parietal network. It overlapped most with formal logic problems, less with algebra, and only a little with language or general executive tasks. The patterns of activity were even different enough to tell a for loop from an if statement.

One honest caveat, which the paper's own reviewers raised: only 15 people. That's normal for this kind of scan, but it's a reason to hold the details loosely.

So why did language skill predict who learned Python?

Here's where it gets interesting.

In 2020, Chantel Prat's lab at the University of Washington took 36 adults who had never coded and gave them ten 45-minute Python lessons on Codecademy (Scientific Reports, 2020). Before the lessons, everyone did a battery of tests: maths, language aptitude, working memory, reasoning, plus a five-minute resting EEG.

Across the outcomes, fluid reasoning and working memory explained about 34% of the differences between people. Language aptitude explained 17%. Numeracy explained 2%.

Two percent.

"Many barriers to programming... are centered around the idea that programming relies heavily on math abilities, and that idea is not born out in our data," Prat told UW News.

This doesn't contradict the scanner studies as much as it seems. The MIT team made the same point: learning to program may lean on language-learning skills (new vocabulary, new grammar), even if reading code you already know runs mostly on the hard-thinking network.

There's one more hint about change with experience. At the University of Virginia, Benjamin Floyd, Tyler Santander and Westley Weimer scanned 29 people reviewing code and English prose (ICSE 2017). A classifier could tell the two apart from brain activity about 79% of the time, and it got worse at it for more skilled participants. Their code and prose looked more alike. But a 2019 replication with wearable sensors (Fucci et al.) found no link with expertise. So treat that one as an open question.

What this means at your desk

You don't have a code module. You have a general-purpose "think hard" network that juggles a handful of things at once, and code fills it up quickly.

A few things follow from that.

"I'm not a maths person" is a weak reason not to code. In the one study that measured it head to head, numeracy was the smallest predictor of learning Python.

The early weeks are a vocabulary problem. Keywords, built-ins, what map returns. That's the part where language-learning habits pay off. Short, repeated recall beats rereading the docs.

Reading code is a working-memory problem. Every variable you have to track takes a slot in that network. Small functions and honest names aren't style points. They're load management.

A watercolour of a programmer at a laptop at night with glowing loops and branching arrows floating above their head

Try this today

Every one of these studies used the same task: look at code and predict what it does before running it.

Pick a snippet you didn't write. Hide the output. Say out loud what it'll print and why, line by line. Then run it.

When you're wrong, that's the useful part. You've just found the exact thing your head was modelling badly.

I do a version of this with the tutorials and talks I save. I built Recl for that: you save a video or article, it gives you the key takeaways, and later it asks you a question about it instead of letting it rot in a bookmarks folder. You can also ask your own saved library a question and get the answer with sources.

Recl's Ask your library screen answering a question from saved items with sources listed

Your brain didn't evolve to read code. It learned to anyway, by borrowing the machinery it uses for everything hard. Give that machinery fewer things to hold, and more chances to be wrong early.


I'm Asutosh. I write about how the brain learns and remembers, and I build Recl, a tool for remembering what you watch and read.

Sources

  • Siegmund, J., et al. (2014). Understanding understanding source code with functional magnetic resonance imaging. ICSE 2014. https://doi.org/10.1145/2568225.2568252
  • Ivanova, A. A., et al. (2020). Comprehension of computer code relies primarily on domain-general executive brain regions. eLife, 9, e58906. https://elifesciences.org/articles/58906
  • Liu, Y.-F., Kim, J., Wilson, C., & Bedny, M. (2020). Computer code comprehension shares neural resources with formal logical inference in the fronto-parietal network. eLife, 9, e59340. https://doi.org/10.7554/eLife.59340
  • Prat, C. S., Madhyastha, T. M., Mottarella, M. J., & Kuo, C.-H. (2020). Relating natural language aptitude to individual differences in learning programming languages. Scientific Reports, 10. https://www.nature.com/articles/s41598-020-60661-8
  • Floyd, B., Santander, T., & Weimer, W. (2017). Decoding the representation of code in the brain: An fMRI study of code review and expertise. ICSE 2017. https://doi.org/10.1109/ICSE.2017.24
  • Fucci, D., Girardi, D., Novielli, N., Quaranta, L., & Lanubile, F. (2019). A replication study on code comprehension and expertise using lightweight biometric sensors. ICPC 2019. https://arxiv.org/abs/1903.03426

Top comments (0)