Swear By My Code
Written by Harry Fairhead   
Wednesday, 12 July 2023

Open source code that contains swearwords is higher quality than code than does not. And although you might initially find this surprising, psychology offers plenty of explanations why it should be the case and there's lots of anecdotal evidence too. 

The hypothesis that Jan Strehmel set out to investigate in his Bachelor Degree thesis for Karlsruhe Institute of Technology, was that there would be no statistical difference between GitHub repositories that contain swearwords and the control group of repositories that may or may not contain swearwords. Using the GitHub API he collected more than 3,800 repositories of C code containing swearwords and a further 7,600 repositories written in C as "the general population". 

Testing for code quality was done with SoftWipe, an open source tool for automatically checking the software quality of a C/C++ program that returns a score in the range from 0 (low) to 10 (high), developed at the Heidelberg Institute for Theoretical Studies by a group including Alexandros Stamatakis, Strehmel's supervisor. The result was that repositories containing swear-words exhibited a statistically significant higher average code-quality (5.87) compared to the general population (5.41):

swaerwords chart

The conclusion to the thesis states:

We find that open source code containing swearwords exhibit significantly better code quality than those not containing swearwords under several statistical tests. We hypothesise that the use of swearwords constitutes an indicator of a profound emotional involvement of the programmer with the code and its inherent complexities, thus yielding better code based on a thorough, critical, and dialectic code analysis process.

Another possible explanation for the findings referred to in the thesis is that swearing in the workplace acts as a form of stress relief  which in turn could then improve focus and therefore code quality.

The Desde Linux blog which reported Strehmel's thesis in Open source with profanity in comments is statistically better than code without it quotes Timothy Jay, emeritus professor of psychology. at the University of Massachusetts:

The benefits of swearing have only emerged in the last two decades, as a result of a lot of research on the brain and emotions, as well as much better technology for studying brain anatomy

Other psychologists point to examples where swearing  can relieve pain, increase physical performance, and to evidence that profanity, when used strategically, may increase student engagement.

It also has to be remembered that swearing isn't always negative - phrases like "f*ing amazing" are used to express a positive response both in speech and on social media.

There is also the simple fact that you have to be confident to make such bold comments. It is one thing to say, "I think this might not be the most efficient way of doing this" and quite another to say "what the #!?# is this doing here!" If you are that confident about your opinion you are probably going to be right, well you had better be right. Such confidence is probably correlated with competence and hence higher code quality.

Open-source software development and strong language do seem to go hand in hand. Until recently when he decided to moderate his demeanour, Linus Torvalds was known for his use of profanity that was not confined to comments on his own code but was liberally employed when commenting on code commits to Linux. While many were prepared to put up with this, and were even entertained by his creative use of bad language, others were intimidated or deterred from engaging in open source - hence the need for change.

However the idea that confident, competetent programmers are happy to express the highs and lows of programming with swear words seems perfectly rational to me.

swaerwords comment

More Information 

Open source with profanity in comments is statistically better than code without it

Is there a Correlation between the Use of Swearwords and Code Quality in Open Source Code? (pdf)

Banner


Node.js 22 Adds WebSocket Client
29/04/2024

Node.js 22 has been released with support for requiring ESM graphs, a stable WebSocket client, and updates of the V8 JavaScript engine.



Explore SyncFusion's Blazor Playground
16/04/2024

Syncfusion has provided an in-browser environment where you can write, compile and run code that uses Blazor components and get it previewed live.


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

 

 

 

 

Last Updated ( Wednesday, 12 July 2023 )