Comparison
Primitive obsessionvsStringly typed
Primitive obsession
money is a decimal, the email is a string, and the validation for both is repeated in nine call sites.
Representing domain concepts with language primitives instead of types of their own, so the rules that go with them have no home. It is the reason the same validation appears everywhere, the reason two identifiers can be swapped without complaint, and the reason a currency-free amount ends up added to another currency. Value objects and tiny types are the direct cure.
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 →