3 ms·
The relevant maxim comes from John Ousterhout's A Philosophy of Software Design, specifically Chapter 10, "The best way to eliminate exception handling complexi
by cratermoon 3y ago
The relevant maxim comes from John Ousterhout's A Philosophy of Software Design, specifically Chapter 10, "The best way to eliminate exception handling complexity is to define your APIs so that there are no exceptions to handle: define errors out of existence".
This approach isn't unique to Rust, though I applaud Piotr Sarnacki for going into detail about how to approach the concept. The undercurrent of design this article suggests is to avoid primitive obsession, and define appropriately constrained types. In the example of concurrency, the HashMap type is, outside of the owner, immutable, unless ownership and mutability becomes part of the type definition.
Too often programmers use String or Integer when they really should be using a domain-relevant type (which might be implemented under the covers with a primitive) enforcing the bounds. For example, using an integer for the Natural Numbers opens up all kinds of issues. Even using unsigned int is wrong, because subtracting a larger number from a smaller number because subtraction of natural numbers is not closed.