All concepts

Magic Strings

Implementing presumably unlikely input scenarios, such as comparisons with very specific strings, to mask functionality.

EverydayConcepts.io

Origin

The term has no single inventor, extending the older concept of "magic numbers" — unnamed numeric literals embedded in code — to unnamed string values. The broader category of "anti-patterns" was formalised by Andrew Koenig in 1995 and codified in the influential 1998 book AntiPatterns by Brown, Malveau, McCormick, and Mowbray. Magic strings gained notoriety alongside object-oriented and scripting languages in the 1990s, in which strings as identifiers became ubiquitous and the cost of silent duplication errors became apparent.

Updated February 22, 2026