Skip to content
SciTools Blog
Menu
  • Home
  • Blog
  • Support
  • Contact
  • Login
  • Pricing
  • Free Trial
Menu

Useful Scripts: Scanning source code for profanity

Posted on July 19, 2021

TL;DR

Profanity has no place in source code. It can be viewed as unprofessional or offensive, and should be avoided whenever possible. Using this custom Python script with Understand, you can quickly scan your project for instances of profanity and scrub them clean.

Details

Warning: This article contains some profanity as part of the samples

As a software developer, you are usually given a fair amount of freedom – freedom to design your code structure, freedom to write comments that help you understand what the code is doing, and freedom to name your variables what you’d like. This freedom is a good and necessary thing, don’t get me wrong, but with this freedom, you also carry the responsibility of maintaining a certain level of professionalism.

While profanity or inappropriate jokes may be used as a way to vent frustration with a coworker’s overly verbose function or annoyance with some legacy code, the source code is simply not the place for it. This type of thing can wind up deeply offending someone, or at the very least making you look bad.

Over the course of a code base’s lifetime, there’s a good chance you won’t be the only developer that sees or uses it – the obvious exception to this being a personal project that lives on your local machine, for instance. Not only could coworkers see it, but the code could eventually be made open-source, or released as a sample – it’s impossible to predict who will see it in the future!

With this in mind, I’ve written a script using Understand’s Python API to scan every single lexeme in a given project and report all cases of profanity. This script was written with a package called better-profanity that uses string comparison to find swear words (and most leetspeak variations of them) in strings.

Note: The package only works with Python 3.4+ and PyPy3.

Usage:

$ python3 "/path/to/profanity.py" "/path/to/my_project.und"

Here’s a simple C++ file we could run the script on:

#include <iostream>
#include <string>

using namespace std;

int main() {
  
  // what is this fucking string even for??
  string str1 = "hello world...";
  
  int shitty_number = 1000;
  
  cout << "program ending" << endl;
  
  return 0;
}

Which would give us the following output via the console:

profanity.py output

From here, we could dig into the source code, clean up these unnecessary instances of foul language, and go about our day feeling good about our virtuous deeds.

Download profanity.py

  • Instagram
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Learn more about Understand's Features

  • Dependency Graph
    View Dependency Graphs
  • Comply with Standards
  • View Useful Metrics
  • Team Annotations
  • Browse Depenedencies
  • Edit and Refactor

Related

Leave a Reply Cancel reply

You must be logged in to post a comment.

  • API
  • Architectures
  • Business
  • Code Comparison
  • Code Comprehension
  • Code Navigation
  • Code Visualization
  • Coding Standards
  • Dependencies
  • Developer Notes
  • DevOps
  • Getting Started
  • Legacy Code
  • Licensing
  • Metrics
  • Platform
  • Plugins
  • Power User Tips
  • Programming Practices
  • Uncategorized
  • Useful Scripts
  • User Stories
  • May 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • April 2023
  • January 2023
  • December 2022
  • November 2022
  • September 2022
  • August 2022
  • May 2022
  • April 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

©2025 SciTools Blog | Design: Newspaperly WordPress Theme