4 ms·
Consider this to be the only function that modifies locations and metadatas. It is the function that is supposed to maintain that invariant. You can pass in loc
by lalaithion 5y ago
Consider this to be the only function that modifies locations and metadatas. It is the function that is supposed to maintain that invariant. You can pass in location and metadata (or make this a method on an object with those values as private members) without changing my point.
Under the rules laid down by the original poster in the link, functions which only modify well-encapsulated types via their public APIs cannot violate invariants.
My code shows that there are "invariant[s] that must be externally enforced" even in code that only deals with well-encapsulated types via their public APIs. And if you don't have explicit error handling, it isn't obvious that the invariant can be broken.
- Spivak 5y ago> well-encapsulated types via their public APIs cannot violate invariants … of those well-encapsulated types. Throwing an exception like this cannot break an internal invariant of the list object which is what the author is saying. You can’t break the list object which sounds crazy by modern standards but in languages without this kind of encapsulation (like C) this can and does happen.
- lalaithion 5y agoThat's a very useful guarantee, I agree, but it's not a good enough reason to not have "try" as a syntax.