Beyond Strict Rules: Assessing the Effectiveness of Large Language Models for Code Smell Detection
This paper evaluates the effectiveness of four large language models in detecting nine code smells across 30 Java projects, revealing that while they excel at identifying structurally straightforward smells, a hybrid strategy combining LLMs with static analysis tools offers superior performance for most smells, though the optimal approach ultimately depends on whether precision or recall is prioritized.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Big Picture: Finding "Bad Habits" in Code
Imagine a massive library of books (software code). Over time, some books get messy. They might have chapters that are too long, pages that repeat the same story, or characters that rely too heavily on others to do their work. In software engineering, these messy patterns are called Code Smells. They aren't bugs that crash the program, but they are like "bad habits" that make the code hard to fix, update, or understand later.
For years, we've used Static Analysis Tools (let's call them "The Rulebooks") to find these smells. The Rulebooks are strict; they follow a checklist. If a method has more than 50 lines, the Rulebook says, "That's a Long Method!" It's fast, but it can be a bit dumb. It might flag a perfectly fine long method just because it's long, or miss a messy short method that looks innocent.
Recently, Large Language Models (LLMs) (let's call them "The Smart Interns") have become famous. These are AI systems that can read and understand code almost like a human. The big question this paper asks is: Can these Smart Interns find the bad habits better than the strict Rulebooks?
The Experiment: A Taste Test with 30 Libraries
To find out, the researchers set up a massive taste test.
- The Menu: They picked 30 popular Java software projects (like choosing 30 different types of restaurants).
- The Menu Items: They looked for 9 specific types of bad habits (Code Smells), such as:
- Long Method: A function that tries to do too much.
- Large Class: A file that is bloated with too many responsibilities.
- Feature Envy: A function that spends more time working on someone else's data than its own.
- The Judges: They didn't just let the AI guess. They asked 76 human developers (students with good training) to manually inspect 268 code snippets and decide: "Is this actually a bad habit, or is it fine?" This created the "Ground Truth" (the official answer key).
- The Contestants: They pitted 4 different Smart Interns (DeepSeek-R1, GPT-5 mini, Llama-3.3, and Qwen2.5-Code) against the Rulebooks (traditional tools like JDeodorant and PMD).
The Results: Who Won?
The results were a mix of "The Interns are amazing" and "The Rulebooks still have their place."
1. The Easy Stuff: The Interns Shine
For smells that are easy to count or measure, the Smart Interns were fantastic.
- Analogy: If the bad habit is "This book is 500 pages long," the Interns can count the pages just as well as the Rulebook, but they understand the context better.
- The Winners: For smells like Long Method and Large Class, the AI models performed very strongly, often matching or beating the strict tools.
2. The Tricky Stuff: It Depends on the Intern
For smells that require understanding why code is written a certain way, the results were mixed.
- Analogy: Imagine a character in a story who talks to a neighbor too much. Is that "Feature Envy" (bad) or just good teamwork? The Rulebook might miss it entirely. One Smart Intern might say, "Yes, that's bad!" while another says, "No, that's fine."
- The Finding: Different AI models were good at different things. For example, one model was great at spotting "Feature Envy," while another was better at "Intensive Coupling." There was no single "Super AI" that was perfect at everything.
3. The Hardest Stuff: Both Struggle
For the most subjective smells, like Refused Bequest (a child class that ignores its parent's rules) or Shotgun Surgery (a tiny change that breaks things everywhere), both the Rulebooks and the Smart Interns struggled.
- Analogy: These are like subtle social awkwardness in a group chat. It's hard to define exactly when it becomes a problem. Even the smartest AI and the strictest rulebook had a hard time agreeing on these.
The Secret Weapon: The "Voting Committee"
The researchers tried a clever trick. Instead of asking just one AI or just one Rulebook, they asked everyone (all 4 AIs + 2 Rulebooks) to vote on every piece of code. If at least 3 out of 6 said, "This is a smell," they counted it as a smell.
- The Result: This "Committee" approach was the best at finding everything (high Recall). It caught almost all the bad habits, even the tricky ones.
- The Catch: Because it was so eager to catch bad habits, it also flagged some clean code as "smelly" (False Positives).
- The Lesson: If you want to make sure you don't miss any problems, use the Committee. If you want to avoid annoying your team with false alarms, pick the single best expert for that specific job.
The Bottom Line
- For simple, structural problems (like code that is too long or too big), AI is a powerful tool that works as well as, or better than, traditional tools.
- For complex, context-heavy problems, specialized tools or specific AI models are still better than a general "one-size-fits-all" approach.
- The Best Strategy: It depends on what you value.
- If you want safety (finding every possible issue), combine the AI and the tools (The Committee).
- If you want precision (avoiding false alarms), pick the specific tool or AI model that is best at that specific type of smell.
In short, the Smart Interns are ready to help, but they work best when you know which Intern to ask for which job, or when you let them work together with the old-school Rulebooks.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.