Hacker News new | ask | show | jobs
by Tcepsa 14 days ago
Haha same! All you need are primitives and maps and lists and first class functions! (Though good decomposition syntax is up there as well; it can be really helpful for telling what a given thing needs the map to include!)
1 comments

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.

Apologies for the slow reply; it has been a chaotic week!

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.

> Awesome, how do you ensure clients of your code always do the correct operations on your data?

Either the data type is opaque (as in you shouldn’t mess with it and you should use the provided api) or it’s just normal primitives and thus no restrictions.

You don’t usually reach into data structures to modify their properties, especially if it’s for foreign modules.