jargon

Comparison

Primitive obsessionvsTiny type

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 →

Tiny type

the two ids were both strings, you passed them in the wrong order, and nothing complained until production.

A one-field value object wrapping a primitive so the type system can tell a customer id from an order id. It is the cheapest available cure for primitive obsession and for the class of bug where two same-typed arguments get swapped. The objection is boilerplate, which is real in some languages and nearly zero in those with value classes or type aliases with checking.

Full entry →

Related comparisons