Posts
read more
The Robustness Principle and Type Annotations
This is one of those things that seems obvious, but in my experience is frequently overlooked. I’ve had versions of this conversation with several coworkers over the years, so I figured it was worth writing down. The idea is that when annotating functions and methods, parameters should accept the widest type that the function or method will work correctly with, and return values should be as concrete as possible. This probably sounds familiar as it is effectively the Robustness Principle (aka Postel’s Law):