Common Antipatterns
Common software antipatterns to avoid across all languages and architectures.
God Object
Problem: One class/module does everything.
Example:
1class Application:
2 def connect_database(self): pass
3 def send_email(self): pass
4 def process_payment(self): pass
5 def generate_report(self): pass
6 def authenticate_user(self): pass
7 # ... 50 more methods
Solution: Split into focused, single-responsibility classes.
Spaghetti Code
Problem: Unstructured, tangled control flow.
Symptoms:
- Deep nesting (5+ levels)
- Goto statements
- No clear separation of concerns
- Hard to follow logic
Solution: Refactor into functions, use early returns, apply design patterns.
Golden Hammer
Problem: Using the same solution for every problem ("If all you have is a hammer...").
Example: Using microservices for a simple CRUD app, or using blockchain for everything.
Solution: Choose the right tool for the job.
Premature Optimization
Problem: Optimizing before knowing where bottlenecks are.
Quote: "Premature optimization is the root of all evil" - Donald Knuth
Solution: Profile first, optimize later.
Cargo Cult Programming
Problem: Copying code/patterns without understanding why.
Example: Adding try-catch everywhere "because best practices say so".
Solution: Understand the reasoning behind patterns before applying them.
Big Ball of Mud
Problem: No discernible architecture, everything depends on everything.
Solution: Introduce layers, modules, and clear boundaries.
Lava Flow
Problem: Dead code that nobody dares to remove.
Solution: Use version control, remove unused code confidently.
Copy-Paste Programming
Problem: Duplicating code instead of abstracting.
Solution: DRY principle - extract common functionality.
Magic Numbers
Problem: Hardcoded values without explanation.
1# β Bad
2if status == 3:
3 process()
4
5# β
Good
6STATUS_APPROVED = 3
7if status == STATUS_APPROVED:
8 process()
Shotgun Surgery
Problem: One change requires modifications in many places.
Solution: Better abstraction and encapsulation.
Related Snippets
- C/C++ Code Smells
Common code smells in C/C++ and how to fix them. Memory Leaks 1// β Bad 2void β¦ - C/C++ Secure Coding
Secure coding practices for C/C++ applications. Buffer Overflow Prevention 1// β β¦ - C/C++ Vulnerability Checks
Tools for checking vulnerabilities in C/C++ code. Valgrind 1# Install 2sudo apt β¦ - Common Code Smells
Common code smells to watch for during code reviews with examples and fixes. β¦ - Developer Pre-Submission Checklist
Comprehensive checklist for developers before submitting a pull request. Code β¦ - Go Code Smells
Common code smells in Go and how to fix them. Ignoring Errors 1// β Bad 2result, β¦ - Go Secure Coding
Secure coding practices for Go applications. SQL Injection Prevention 1// β β¦ - Go Vulnerability Checks
Tools for checking vulnerabilities in Go code. Govulncheck 1# Install 2go β¦ - Haskell Code Smells
Common code smells in Haskell and how to fix them. Partial Functions 1-- β Bad: β¦ - Haskell Secure Coding
Secure coding practices for Haskell applications. SQL Injection Prevention 1-- β β¦ - Haskell Vulnerability Checks
Tools for checking vulnerabilities in Haskell code. Cabal Outdated 1# Check β¦ - Python Code Smells
Common code smells in Python and how to fix them. Mutable Default Arguments 1# β β¦ - Python Secure Coding
Secure coding practices for Python applications. SQL Injection Prevention 1# β β¦ - Python Vulnerability Checks
Tools for checking vulnerabilities in Python code. Safety - Dependency Scanner β¦ - Reviewer Checklist
Comprehensive checklist for code reviewers to ensure thorough and constructive β¦ - Rust Code Smells
Common code smells in Rust and how to fix them. Unwrap/Expect Abuse 1// β Bad β¦ - Rust Secure Coding
Secure coding practices for Rust applications. SQL Injection Prevention 1// β β¦ - Rust Vulnerability Checks
Tools for checking vulnerabilities in Rust code. Cargo Audit 1# Install 2cargo β¦ - TypeScript Code Smells
Common code smells in TypeScript and how to fix them. Using any 1// β Bad β¦ - TypeScript Secure Coding
Secure coding practices for TypeScript applications. XSS Prevention 1// β β¦ - TypeScript Vulnerability Checks
Tools for checking vulnerabilities in TypeScript/JavaScript code. npm audit 1# β¦