The Golden Hammer is a methodological software anti-pattern in which a team which is very familiar with a particular tool or methodology uses that tool or methodology as a solution to every problem they encounter.   It originates from a popular phrase: "If all you have is a hammer, everything looks like a nail."

Midas's gavel

So what's the solution?  Get a different tool.  Why use a hammer when all you need is a timer?

The Rundown

  • Name: Golden Hammer
  • AKA: Law of the Instrument, Maslow's Hammer
  • Summary: Occurs when a team or individual decides that a particular tool with which they are familiar is the solution to every problem they encounter.  
  • Type: Methodological
  • Common?: CASE DISMISSED! bangs gavel

Tell Me a Story!

What, really?  I already did, three years ago.

Tell It Again!

...Fine.

Ben is a new web developer, after having formerly been a database administrator, and he's been given his first task in this new role. His lead has asked him to implement a new website, one that will be displaying some static content to a small set of visitors in his company.
Ben, having dealt with these kinds of applications before on the database side, immediately begins laying out the database design for this new app. A simple schema and a few hours later, he presents his design to his lead Paula, who has to explain to him that the website isn't expected to change its content frequently enough to warrant using a database at all.
The website was displaying static content, e.g. content that would not change often. Ben had picked up his golden hammer and tried to use it to solve a problem that it wasn't really needed for.

This is a contrived example, to be sure.  I know because I contrived it.  But the problem remains.

Strategies to Solve

Given that the Golden Hammer is a methodological anti-pattern, it requires a solution from people, not processes or technology.  I like to call this solution "the extra five minutes."

tick tick tick tick tick tick tick tick DING!

Whenever you are presented with a problem, and think "I know, I'll use X to solve the problem," spend an extra five minutes searching round the web to find out if this is actually a viable solution.  There are no new problems under the sun, and someone will have done what you are trying to do already, if it is possible to do.  90% of the time, if the solution you want is viable, the first few search hits will tell you so.  Otherwise, if you have to spend more than five minutes to find a blog post, StackOverflow question, or other item that relates to your proposed solution, it may be time to research other ideas.  

This requires a certain amount of self-awareness, which a distressing number of professional developers lack.  There's a reason we ended up with the fedora-wearing shut-in neckbeard stereotype.  But you, dear reader, are unlikely to have this lack of self-awareness, merely because you are reading this blog (or, indeed, any blog).  That shows that you are aware that you can improve, and if I'm being honest, that is the first step to fixing all of these anti-patterns, not just the Golden Hammer.  Self-awareness is the enemy of ignorance.

Summary

The Golden Hammer anti-pattern occurs when you use a familiar solution to attack an unfamiliar problem.  Sometimes this might actually work out, but most of the time it's an inefficient way to solve problems.  Us developers must be aware of the strengths and limitations of all our tools, and know how to find the correct ones when the situation arises.

Now, which one does SOAP? (Image found on Flickr, used under license)

Have you found yourself falling victim to the Golden Hammer?  Or did you witness someone else do the same?  I want to know about it.  Share in the comments! Or else head on back to the series index page to see some more anti-patterns.

Happy Coding!