The hidden brain power behind programming

New research from U-M reveals how stimulation of certain brain regions affects programming performance.
Image source: Google DeepMind

Imagine if the key to programming efficiency resided somewhere in the intricate circuits of the human brain. In a new study, researchers at the University of Michigan have taken us one step closer to understanding the neurological underpinnings of programming by using transcranial stimulation to study certain brain regions’ influence on coding speed and performance.

Their paper, titled “Causal Relationships and Programming Outcomes: A Transcranial Magnetic Stimulation Experiment,” has won a Distinguished Paper Award at the 2024 International Conference on Software Engineering (ICSE) for its significance in shaping our understanding of the brain mechanics underlying programming. By using noninvasive techniques to disrupt specific brain regions, the research team, including CSE PhD students Hammad Ahmad, Madeline Endres, and Priscila Santiesteban; undergraduate students Kaia Newman and Emma Shedden; and CSE Prof. Westley Weimer, has provided measurable evidence that could inform how we train and cultivate future generations of software developers.

“Exploring the cognitive foundations of programming could help us build better, more targeted interventions to help people learn and succeed in computer science,” said Endres, “particularly people who may not have as much incoming preparation or are perhaps retraining for a new job later in life. We are trying to establish causal links to provide empirical backing for the right types of interventions to support these learners.”

It’s been a long-held belief in the software engineering community that spatial reasoning, the ability to think about and mentally manipulate three-dimensional objects, is directly tied to programming performance. The research team sought to interrogate this belief and the possible misconceptions about programming ability that have resulted from it.

“There have been a few neuro-imaging papers that have used MRI machines and other techniques to look at brain activity while participants are working on computer science-adjacent tasks, and there was a suggestion across these papers that the brain region associated with spatial reasoning is correlated with the brain activity seen in programming,” said Ahmad. “There have been pedagogical interventions informed by this correlation that have had varying levels of success, so we wanted to explore whether this correlation is actually a causal link.”

To determine whether the brain region associated with spatial reasoning is indeed tied to programming, the researchers applied a brain stimulation technique commonly used in cognitive science and psychology called Transcranial Magnetic Stimulation (TMs). This method uses a magnetic field to deliver an electric current that temporarily interrupts or enhances brain activity in a target region.

“Rather than having someone do programming tasks and simply observe what’s going on in their brain, we wanted to take it a step further and look at what happens if we actively inhibit or excite activity in certain brain regions and then have people do the same task,” said Ahmad. “If the same brain region is supposed to be responsible for both programming and spatial reasoning, does disrupting activity in that area reduce your ability to program?”

An illustration of the human brain with the motor cortex highlighted and labeled.
A diagram of the human brain’s motor cortex. The researchers in this study applied TMS to the primary motor cortex and the supplementary motor area. Source: McGill University.

The study focused on two specific brain regions to elucidate these effects: the primary motor cortex, which controls voluntary muscle movement; and the supplementary motor area, which is involved in the planning and coordination of movement. An active control group was also used to help ensure the validity of the findings.

“To our knowledge, this is the first application of TMS in a computer science or programming context,” Ahmad stated.

With the aid of colleagues in the Psychology Department, led by Prof. Taraz Lee, the team was able to access and learn how to use the necessary TMS equipment. Because TMS is considered a medical-grade procedure, it requires extensive training, which lasted for about two years before the researchers were ready to apply TMS with participants.

Safety and ethical considerations were paramount, as participants were required to undergo meticulous screening before joining the study. Participants then came in for a series of experimental sessions, beginning with a functional MRI scan to provide an anatomical map of the brain for targeted stimulation.

“When participants come in for their TMS session, we upload their brain scan data into the system,” Ahmad explained, “and use precision tools including trackers and cameras to pinpoint the target area. The system also provides real-time feedback so we can adjust the target and orientation as needed during the process.”

The participant is then fitted with a coil which delivers the stimulation. When an electric current is sent through the coil, it generates a magnetic field, which then induces current in the brain region of interest to excite or inhibit neural activity.

Despite the seeming complexity of the process and its preparation, the actual stimulation is relatively brief. “Setup before participants arrive can take a couple of hours, but the TMS stimulation itself is only 40 seconds,” said Ahmad.

In addition to its brevity, TMS stimulation is noninvasive and temporary, with effects lasting just half an hour and brain function returning to complete normality afterward. While some might know TMS for its roots in psychological treatment, including for severe depression, these applications are much more intensive and occur for longer periods of time across multiple sessions. Its usage in this study was much more targeted, with no lasting effects for participants.

A view from the back of Hammad Ahmad performing TMS on Priscila Santiesteban. Ahmad is holding a black device about the size of a hairdryer up to Santiesteban's head. The device is hooked up to a box-shaped machine that is generating an electric pulse. Ahmad looks at a computer screen where a scan of Santiesteban's brain is projected.
Study author Hammad Ahmad performs the TMS procedure with coauthor Priscila Santiesteban.

Over 20 participants were eventually narrowed to 16 individuals whose data was suitable for analysis. The selection of participants was diverse, including both computer science students and professional developers. Participants were required to demonstrate a solid foundational knowledge in data structures, based on the nature of the programming questions posed in the study.

Once TMS was performed in the targeted brain region, participants were asked a series of programming questions. Participants’ response times to these questions, rather than the correctness of their answers, were used to assess programming performance. The team employed multilevel regression for data analysis, a robust statistical method for understanding the influence of one or more predictor variables on an outcome variable.

The team’s findings were surprising. Contrary to prior studies indicating a correlation between brain activity involved in spatial reasoning and programming, the researchers discovered no evidence of causality.

“We did not find a direct causal link between brain activity in the primary motor cortex or supplementary motor area and programming after doing TMS,” said Ahmad. “These results disagree with the correlations reported in several previously published studies.”

Despite failing to demonstrate a causal link in these brain regions, the study did uncover an intriguing detail. TMS seemed to explain about 2% of the variance in computing outcomes, a small but notable effect that warrants further exploration.

“TMS did have an impact, although we’re not sure of its precise nature yet,” said Shedden. “This is what we’ll be looking into in our future work.”

The team’s ongoing research will follow this line of inquiry, exploring how neurology activity in other areas of the brain might affect programming ability.

“Our next step will be to examine other brain regions that the literature suggests might be impactful,” said Endres. “TMS did something, but maybe the specific regions we were focusing on weren’t as related as was previously thought, and there might be other factors at play that we aren’t aware of yet.”

The team’s main finding, distilled by Ahmad, is that several brain regions could potentially contribute to programming ability, and that more research is needed to better inform possible interventions based on this knowledge. “Our research serves as a sort of cautionary tale that cognition is multifaceted and complex,” he said. “We should exercise caution when basing educational or training interventions on assumed correlations before establishing clear, causal connections.”

Endres emphasized the implications of their findings and future explorations for computer science learners. “Understanding the causal relationships behind these skills has the potential to enhance how we assist those looking to learn programming and enter the computer science industry, especially individuals who may not have a traditional background in the field.”

Their findings show that spatial reasoning is just one of many skills that could be important for succeeding in computer science, and that exploring how other abilities contribute to programming performance is crucial in effectively supporting new developers.

“There is this idea that to be good at computer science, you must also be good at specific other fields, such as math and science, but recent work in the cognition of software has shown that that’s not necessarily the case,” said Shedden. “We’re expanding our research to look at other foundational skills, including reading comprehension, which aren’t traditionally associated with computer science success.”

With these explorations, the team looks to change misconceptions about the neurological foundations of programming, underscoring the importance of empirical evidence in guiding educational practices and opening up the field with more inclusive training methods.

“Ultimately, our goal is to inform more effective interventions that enable a wider range of individuals to thrive in computer science,” said Ahmad.