Golden Hammer.
The golden hammer is the habit of applying one familiar tool, language or design to every problem, including problems it fits poorly.
The golden hammer, also known as the law of the instrument, the law of the hammer or Maslow's hammer, is a cognitive bias that involves an over-reliance on a familiar tool. In software engineering the term names an antipattern: a familiar technology, language or design is applied to every new problem, including problems it fits poorly, simply because the team already knows it. Abraham Maslow wrote in 1966, "it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail."
The concept is attributed both to Maslow and to Abraham Kaplan, although the hammer and nail line may not be original to either of them.
History
The English expression "a Birmingham screwdriver", meaning a hammer, refers to the practice of using the one tool for all purposes, and predates both Kaplan and Maslow by at least a century.
In 1868, a London periodical, Once a Week, contained this observation: "Give a boy a hammer and chisel; show him how to use them; at once he begins to hack the doorposts, to take off the corners of shutter and window frames, until you teach him a better use for them, and how to keep his activity within bounds."
Kaplan
The first recorded statement of the concept was Abraham Kaplan's, in 1964: "I call it the law of the instrument, and it may be formulated as follows: Give a small boy a hammer, and he will find that everything he encounters needs pounding."
In February 1962 Kaplan, then a professor of philosophy, gave a banquet speech at a conference of the American Educational Research Association that was being held at UCLA. An article in the June 1962 issue of the Journal of Medical Education stated that "the highlight of the 3-day meeting ... was to be found in Kaplan's comment on the choice of methods for research. He urged that scientists exercise good judgment in the selection of appropriate methods for their research. Because certain methods happen to be handy, or a given individual has been trained to use a specific method, is no assurance that the method is appropriate for all problems. He cited Kaplan's Law of the Instrument: 'Give a boy a hammer and everything he meets has to be pounded.'"
In The Conduct of Inquiry: Methodology for Behavioral Science (1964), Kaplan again mentioned the law of the instrument saying, "It comes as no particular surprise to discover that a scientist formulates problems in a way which requires for their solution just those techniques in which he himself is especially skilled." And in a 1964 article for The Library Quarterly, he again cited the law and commented: "We tend to formulate our problems in such a way as to make it seem that the solutions to those problems demand precisely what we already happen to have at hand."
Tomkins and Colby
In a 1963 essay collection, Computer Simulation of Personality: Frontier of Psychological Theory, Silvan Tomkins wrote about "the tendency of jobs to be adapted to tools, rather than adapting tools to jobs". He wrote: "If one has a hammer one tends to look for nails, and if one has a computer with a storage capacity, but no feelings, one is more likely to concern oneself with remembering and with problem solving than with loving and hating." In the same book, Kenneth Mark Colby explicitly cited the law, writing: "The First Law of the Instrument states that if you give a boy a hammer, he suddenly finds that everything needs pounding. The computer program may be our current hammer, but it must be tried. One cannot decide from purely armchair considerations whether or not it will be of any value."
Abraham Maslow
Maslow's hammer, popularly phrased as "if all you have is a hammer, everything looks like a nail" and variants thereof, is from Abraham Maslow's The Psychology of Science, published in 1966. Maslow wrote: "I remember seeing an elaborate and complicated automatic washing machine for automobiles that did a beautiful job of washing them. But it could do only that, and everything else that got into its clutches was treated as if it were an automobile to be washed. I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail."
Manifestations
Computer programming
The notion of a golden hammer, "a familiar technology or concept applied obsessively to many software problems", was introduced into information technology literature in 1998 as an anti-pattern: a programming practice to be avoided.
Software developer José M. Gilgado has written that the law is still relevant in the 21st century and is highly applicable to software development. Many times software developers, he observed, "tend to use the same known tools to do a completely new different project with new constraints". He blamed this on "the comfort zone state where you don't change anything to avoid risk. The problem with using the same tools every time you can is that you don't have enough arguments to make a choice because you have nothing to compare to and is limiting your knowledge." The solution is "to keep looking for the best possible choice, even if we aren't very familiar with it". This includes using a computer language with which one is unfamiliar. He noted that the product RubyMotion enables developers to "wrap" unknown computer languages in a familiar computer language and thus avoid having to learn them. But Gilgado found this approach inadvisable, because it reinforces the habit of avoiding new tools.
Example
A team fluent in regular expressions reaches for them even to read JSON. The pattern picks up the first "total" it finds — in the sample payload, a line item's — misreads numbers such as 1.5e3 and silently returns 0.0 when the field is missing.
import re
# order_total('{"items": [{"total": 5}], "total": 1.5e3}') returns 5.0, not 1500.0
def order_total(payload: str) -> float:
match = re.search(r'"total"\s*:\s*([0-9.]+)', payload)
return float(match.group(1)) if match else 0.0
A JSON parser understands the whole format and fails loudly on malformed input: choose the tool that fits the data, not the one the team knows best.
import json
def order_total(payload: str) -> float:
return float(json.loads(payload)["total"])
Adapted from the Wikipedia article “Law of the instrument” (revision 1352498338), available under the CC BY-SA 4.0 license; the text has been edited and examples added.