3 ms·
Interesting article, but if one considers the possibility of overflow, the invariants in some of the examples aren't true. Which doesn't mean the article is _w
by eschneider 8y ago
Interesting article, but if one considers the possibility of overflow, the invariants in some of the examples aren't true.
Which doesn't mean the article is _wrong_ so much as it demonstrates one needs to prove the invariants are actually true.
- lifthrasiir 8y agoSeveral static analyzers (like Frama-C [1]) can extract loop invariants and try to prove them, giving you the best of both worlds. [1] https://frama-c.com/ https://frama-c.com/
- jerf 8y agoOn a similar note, for max and min algorithms you actually do have a sensible initial element, which is the min or the max integer for the integer type in question. However, you have to make sure this value can't escape into the caller's context (unless it really is the max value); calling max or min with an empty list ought to be an error in whatever the appropriate local error idiom is. The article (reasonably appropriately) glossed over that.