|
|
|
|
|
by oblio
14 days ago
|
|
Awesome, how do you ensure clients of your code always do the correct operations on your data? With static types it's obvious and you generally have to work hard (and in non intuitive ways) to mess up. This becomes more important as team sizes grow. |
|
The short answer is, "you don't"; without a strong type system you cannot ensure that clients always do the correct operations on your data. (Edit: A strong type system alone is not enough; it must also be correctly leveraged!)
The longer answer is, "Roughly the same way you do with less-strongly-typed languages like C or Java." You embrace Postal's Law/the Robustness Principle (thus try to do sensible things with the sorts of outputs you are likely to receive), you fail early and loudly with things that you cannot do sensible things with, you implement tests that demonstrate the various supported use-cases, you use clear variable names to the extent that you can, you provide guidance via documentation. With Clojure in particular, you can also do destructuring directly in the function signature, which provides additional clues as to what the arguments are expected to look like.