-
Notifications
You must be signed in to change notification settings - Fork 0
TypesReducingEntropy
A good type system lets the programmer precisely describe the set of possible referents of an Identifier.
I once saw a React component that took 25 input props. 25! Assuming each prop has at least two meaningfully different possible values (and it would have to, to be useful) that puts the lower bound of the number of test cases you'd need to fully cover the code's behavior at 33 million.
But of course, that's only true if the props are all independent—and in this case (as in likely every other case of this scenario where the code can actually be comprehended by a human with sufficient knowledge of the system) they were not independent. Certain values of some props rendered other props meaningless. Other props were simply treated as opaque values that were passed along to subcomponents—a case of the OpaqueParameter symptom of DeepHierarchy The actual number of meaningfully different combinations of inputs was probably less than 20.
When types are imprecise, we can still reason about the system by applying knowledge we've gained elsewhere—about the application domain, and about other parts of the program. However, if we do that, we've missed an opportunity—the types could be teaching us that knowledge.