No Naked Primitives

cedd burge
RES Software Team
Published in
1 min readOct 2, 2020

No naked primitives is an optional constraint that we use when programming in our Code Kata’s.

All primitive values, such as booleans, numbers and strings must not be part of the public interface of a class or module. This avoids the Primitive Obsession code smell.

Data structures such as arrays, lists and dictionaries can also be considered as primitives.

This rule is designed to exercise our ability to use the type system of the language we are working in.

For example, an integer representing a person’s age can cause problems, because many integers, and operators upon them are invalid. Instead we would create an Age Value Object (Object oriented languages) or Type (Functional languages).

Another example is a shopping basket, which looks list a list of items at first glance. However a general purpose list implementation offers many operations that would be invalid for a shopping basket (such as each_cons in ruby. It would also not have a lot of operations that a shopping basket should have, such as total, or delivery_cost.

--

--