Skip to main content

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 any with specific TypeScript types.
  • Extract repeated code snippets into a separate folder src/lib or src/utils.
  • Ensure that all error messages are actually logged and not hidden in empty catch blocks.

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.
/ Frequently Asked QuestionsSchema.org FAQPage

FAQ: AI Code Smells

It is not necessarily an error that breaks the program right now. It is a marker of poor architecture or negligence that indicates the code was written hastily and will inevitably create a multitude of bugs as the project evolves.
/ Internal links
All terms