Comparison
Magic numbervsStringly typed
Magic number
there is a 3 in the middle of the expression and nobody left a note saying which three that is.
An unnamed literal embedded in code, carrying meaning that only exists in the author's head. The cost is not readability alone: the same value appearing in two places cannot be told from a coincidence, so changing one is a guess. Naming it is the smallest refactoring in this corpus and among the highest-return.
Full entry →Stringly typed
the status is a string, the comparison was misspelled, and the branch silently never ran.
Using strings where a type would do — statuses, keys, identifiers, enumerated choices — so the compiler cannot help and every comparison is a spelling test. It is primitive obsession's most common form and its most damaging, because a wrong string does not fail, it just does not match. An enum, a sum type or a tiny type removes the entire class of bug.
Full entry →