14 Apr
2019
14 Apr
'19
11:48 p.m.
On 15/04/2019 08:58, Emil Dotchevski wrote:
Yes, but the question was about the benefits of the never-empty guarantee. If the never-empty guarantee doesn't help with maintaining higher level invariants, then what benefit does it bring?
If the design allows for one more state, then that state must be handled: various functions in the program must check "is the object empty" and define behavior for that case. The benefit of the never-empty guarantee is that no checks are needed because the object may not be empty.
As I've said elsewhere, I don't see the difference between "is this empty" and "did this unexpectedly change type", except that the former is easier to detect (and hence better).