AI Code Smells
Typical antipatterns and markers of synthetic code ('code smells' from AI). Excessive obvious comments, utility duplication in every file, fake mocks, and nonsensical try-catch blocks that indicate unchecked generation.
1. Concept Overview & Systemic Problem
Any experienced Senior Engineer can, within 5 seconds during an interview or repository audit, say: “This code was written by someone who knows what they are doing, while this one was just blindly copied from a chatbot without any review.”
Artificial intelligence writes quickly, but it has specific manners and "bad habits" that are referred to in the industry as AI Code Smells.
Understanding these markers is essential for every newcomer: it will help you timely clean your project of synthetic debris and appear as a professional developer in the eyes of colleagues and clients.
2. Key Markers of AI-Generated Code
┌─────────────────────────────────────────────────────────────┐
│ TOP 4 AI CODE SMELLS │
├─────────────────────────────────────────────────────────────┤
│ 1. 📢 Obvious Captain Comments: │
│ // Assigning a value to variable a │
│ const a = 10; // This is the number ten │
├─────────────────────────────────────────────────────────────┤
│ 2. 🖨️ Utility Duplication in Every File: │
│ Instead of importing a common function `formatDate()`, │
│ AI copies the same function across 15 lines in 7 │
│ different components │
├─────────────────────────────────────────────────────────────┤
│ 3. 🙈 Empty Error Handling Blocks: │
│ try { doSomething(); } catch (e) { /* do nothing */ } │
│ (An error occurs, but you will never know about it) │
├─────────────────────────────────────────────────────────────┤
│ 4. 🤹 Overcomplicating Simple Tasks: │
│ Creating 3 classes, a factory, and an interface for │
│ a single mathematical operation of adding two numbers │
└─────────────────────────────────────────────────────────────┘
3. Transforming Synthetic Code into Professional Code
Compare the two code snippets:
❌ Before (Typical Raw AI Output):
// Function that checks the user
function checkUser(user: any) {
try {
// If the user exists
if (user != null) {
// Return true
return true;
}
} catch (err) {
console.log("Error");
}
return false;
}
✅ After (Cleaned Engineering Code):
export function isUserActive(user: User | null): boolean {
return Boolean(user?.isActive);
}
4. Project Cleanup Checklist Before Release
- Remove all obvious comments that repeat what is already stated in the variable name.
- Check types: replace all careless
anywith specific TypeScript types. - Extract repeated code snippets into a separate folder
src/liborsrc/utils. - Ensure that all error messages are actually logged and not hidden in empty
catchblocks.
5. Pitfalls, Common Mistakes & Security
- Overlooking AI Patterns: Failing to recognize AI Code Smells can lead to technical debt and maintenance challenges.
- Ignoring Code Reviews: Relying solely on AI-generated code without human review can introduce subtle bugs and architectural flaws.
- Neglecting Documentation: AI-generated code often lacks context; ensure that documentation is thorough to aid future developers.
FAQ: AI Code Smells
Related terms
Diff-First Mindset: The Art of Reviewing Changes
A fundamental paradigm shift for developers in the AI era (Diff-First Mindset). Transitioning from mechanical text entry to rapid visual assessment of red and green highlighted code changes (git diff) before approval.
AI as Code Reviewer (Bug Detection Before Release)
A methodology for utilizing language models as a stringent senior engineer for automated code audits (Code Review). It identifies hidden security vulnerabilities, memory leaks, and architectural bugs before the software rollout.
AI Slop: Codebase Contamination
A systemic phenomenon of codebase degradation due to the mass addition of low-quality, verbose, overly complex, or duplicated code generated by language models without architectural oversight.