Programmers have a tendency to write functions that take types that are too generic for what the functions actually want.
The most common form of this is called Boolean Blindness
where a function takes boolean arguments that don't actually say what they want. An example that comes to mind is widget.paint(true);
. It's impossible to say what that boolean parameter does without looking up the documentation. The general solution is to either take an enum
(short for enumeration) or an approximation thereof. It'd look something like widget.paint(WidgetPaintMode.Immediate);
.
In generic this is called Primitive Obsession
. Functions that take integers, booleans, strings, and other highly general types. And the solution is to create a more specialized type, either by wrapping the type in a wrapper or creating a new type type to represent the concept, ideally making it impossible to represent impossible values.
Programmers also have an error handling strategy where they return a type that represents *either