Golden Hammer
Misapplying a familiar technology to everything.
“When all you have is a hammer, everything looks like a nail.” – Abraham Maslow
Over-reliance on one tool.
Signs of Use (Symptoms)
- Using a relational database for a graph problem.
- Using XML for everything (logic, config, data).
- Using a specific framework (e.g., React) for static text pages.
Why it is bad (Consequences)
- Inefficiency: The tool is likely poor at the specific job.
- Complexity: Forcing a square peg in a round hole requires adapters/hacks.
- Performance: Suboptimal performance.
Why it happens (Root Cause)
Familiarity. Learning new tools takes time; using the known one is “safe” (but wrong).
When it might be okay (Exceptions)
- Very small teams or prototypes where introducing a new stack is too costly.
Explanation
Problem
You know SQL well. You need to store hierarchical tree data. You write complex recursive CTEs.
The Flaw
A Graph DB or even a document store might handle trees natively. SQL is the wrong tool (hammer).
Real world analogy
Using a screwdriver to pound in a nail because you don’t want to go to the garage to get a hammer.
Refactoring Solution
- Evaluate tools: Research the right tool for the job.
- Education: Learn new paradigms (NoSQL, Functional, etc.).
Pros and Cons (of the Antipattern)
| Pros (Why people do it) | Cons (The price you pay) |
|---|---|
Comparison
- Related Antipatterns: Cargo Cult Programming.
- Related Principles: Right Tool for the Job.
Code example
Typescript
Bad (The Antipattern)
Good (The Fix)
PHP
Bad (The Antipattern)
Good (The Fix)