Consider the following snippet of code:
def paint(numCoats, height): ... numCoats = 2 height = 3 paint(numCoats, height)
height are both stored as integers, under very few circumstances should they be confused. Writing
paint(height, numCoats) should produce an error, no less (preferably compile-time).
Creating a wrapper class every single time. Writing a long clunky class definition for every single parameter + having to import that class in all calling code is unacceptable.
Hungarian notation (in either the parameter name, variables, or both). While there are legitimate (and illegitimate) applications of Hungarian notation, in this case it would be (a) clunky and (b) not prevent mistakes.
Keyword arguments. While keyword arguments would solve the above issues, it might not solve other similar issues.
Summary of requirements
- A minimalist way of just declaring literals or objects to belong to a certain type, and enforcing such type restrictions in scenarios like passing parameters to functions.
I’m not confident I’ve articulated this question well; please comment if I can clarify anything!