Computer programming powers modern society and enabled the AI revolution but little is known about how our brains learn this essential skill. To help answer that question, Johns Hopkins University researchers studied the brain activity of university students before and after they learned how to code.
After the students took a programming course, parts of their brain activated as they read code. Inside these areas, groups of neurons represented the meaning of code. Surprisingly, before the students took the class or knew anything about programming, the same groups of neurons also fired when the students read the programs described in plain English.
The federally-funded work, newly published in the Journal of Neuroscience, provide insight into how and why the human brain programs.
"Many of the things we do in the modern world, our brains didn't evolve to do, including programming, driving, reading and math," said senior author Marina Bedny , a cognitive neuroscientist who studies brain plasticity and development. "A programming class 'recycles' your logic brain areas for code. What we found is that by the time you get to college your brain already has the neural foundations for programming."
AI tools are making coding increasingly accessible. With more people gaining access to programming, Bedny and first author Yun-Fei Liu, a postdoctoral fellow, set out to discover how the human brain adapts as novices begin to learn the skill.
The team used functional magnetic resonance imaging (fMRI) to track the brain activity of undergraduate students before and after they took a semester-long introductory course in Python, a programming language.
When students read code after the course, groups of neurons in a part of the brain responsible for logic, the fronto-parietal regions, represented the meaning of the programs. But even before class, when students read plain English descriptions of the coding programs, the same neurons already activated for the program algorithms.
"Learning to code uses the same neural machinery that we use for logical problem-solving. Everyone has these abilities," said Liu, who investigates how the brain learns educationally relevant cultural skills.
The findings suggest that all humans are equipped with the foundation needed to learn programming—which is mostly logic. And exercising those logic muscles through puzzles, games and everyday dinner-table debates might prime kids for future programming success.
"Someone not familiar with coding might look at Python and feel like they'd never be able to understand it, but our study suggests all of us have the capacity to code," Bedney said. "We might even be born with it."