Ever find yourself staring at a tricky coding problem and thinking, “shit”?
If those thoughts make their way into your code or the associated comments, you’re in good company. When undergraduate student Jan Strehmel from Karlsruhe Institute of Technology analyzed open source code written in the programming language C, he found no shortage of obscenity. While that might be expected, Strehmel’s overall finding might not be: The average quality of code containing swears was significantly higher than the average quality of code that did not.
“The results are quite surprising!” Strehmel said. Programmers and scientists may have a lot of follow-up questions. Are the researchers sure there aren’t certain profanity-prone programmers skewing the results? What about other programming languages? And, most importantly, why would swears correlate with high-quality code? The work is ongoing, but even without all the answers, one thing’s for sure: Strehmel just wrote one hell of a bachelor’s thesis.
Bad words, good code
Strehmel’s supervisor, Bioinformatician Alexandros Stamatakis, started wondering how swears affect code quality after a lab member showed him a graph of the prevalence of swears in various versions of the code underlying Linux. Stamatakis realized he had the perfect tool for asking whether profanity correlates with the quality of code. A program called SoftWipe, developed by his lab, measures adherence to coding standards, such as the use of quality checks and a simple code structure.
To investigate, Strehmel pulled around 3,800 examples of code containing swears, along with 7,600 examples of code that did not, from GitHub. SoftWipe revealed that on average, code containing swears scored about half a point higher on its 10- point scale of code quality than code that did not. “My reaction was that this is cool!” Stamatakis said. He frequently finds himself swearing at his own code, although he tends not to document his outbursts in text. Nonetheless, he wonders if his past curses may help his career progress: “Maybe that has helped me to become a full professor!” he said.
Psychologists have long known that swearing can relieve pain, increase physical performance, and help people shape their personas. In fact, cognitive psychologist Benjamin Bergen from the University of California San Diego—author of the book, What the F: What Swearing Reveals About Our Language, Our Brains, and Ourselves—makes a point to swear once during every college lecture he teaches (in a way that’s unlikely to offend the class) because there’s evidence that profanity, when used strategically, may increase student engagement.
But the link between swearing and code quality has not been examined before, as far as Bergen knows, and the suggestion that there’s a connection is a “very exciting, interesting idea,” he said.
The power of personality
Programmers who swear may be more emotionally engaged with their work than those who don’t, Bergen hypothesized, which could lead them to produce higher-quality products. Alternatively, programmers may include profanity to amuse or shock people who read their code—and if they expect their code to be read, they may put extra effort into it. It’s likely that swearing is a “symptom of something deeper going on,” Bergen said, and he’d like to see future work focus on the underlying cause of the association.
Software engineer Greg Wilson, who now works at the biotech company Deep Genomics, isn’t surprised to see coders’ personalities entering their work through their word choices. Wilson co-founded an organization called The Carpentries that teaches scientists to become good coders and says, “I don’t know anybody who’s good at anything who leaves themselves out of it.”
Wilson is excited to see researchers tackling the question of what makes code good, although Strehmel’s results are preliminary. Coders lag behind other disciplines in terms of how they evaluate their own work, he says. Unlike architects, who have nuanced ways of describing why a building is beautiful, programmers “can say that something is an elegant solution, and then we run out of words.”
He does worry about the impacts that profanity can have if it appears directed at junior programmers, however. Aggressive language has been cited as one factor that discourages people—especially those from groups that are marginalized in STEM—from continuing to work in software engineering. Strehmel and Stamatakis came across the occasional slurs in the code they analyzed, and they agree that there are lines programmers shouldn’t cross. At a certain point, “it stops being funny,” Stamatakis said.
Overall, however, the researchers are enjoying their work, and they have a long list of experiments planned to shore up the results and glean additional insight. When they’re ready to release their final product, Wilson is looking forward to seeing the commit message. He imagines it reading, “holy shit, it worked!”
Saima Sidik is a freelance science writer based in Somerville, Massachusetts. When she’s not writing, she enjoys biking around the city, learning photography, and practicing taekwondo.