On Tue, Feb 2, 2010 at 9:42 PM, Brett Cannon <brett@python.org> wrote:

On Tue, Feb 2, 2010 at 13:05, Antoine Pitrou <solipsis@pitrou.net> wrote:

Le mercredi 03 février 2010 à 06:58 +1000, Nick Coghlan a écrit :

The fact that asserts and if __debug__ blocks get skipped under -O strikes me as more than adequate reason to consider optimised and non-optimised bytecode as different things.

Well, do people rely on this nowadays? With unit testing becoming very common (and recommended) practice, I'm not sure what sprinkling asserts in debug mode really brings.

We might not rely on them, but I am sure there are those who prefer them on top of TDD (or instead of). [...]

FWIW, I'm one of 'those': I find there are assert uses that can't be covered as neatly or directly with unit tests. They're great for documenting loop invariants in complicated algorithms, for example: def xgcd(b, c): """Extended Euclidean algorithm: return integers g, x and y such that b*x + c*y == g and g is a greatest common divisor of b and c.""" g1, g2 = b, c x1, x2 = 1, 0 y1, y2 = 0, 1 while g2: assert x1 * b + y1 * c == g1 and x2 * b + y2 * c == g2 q = g1 // g2 g1, g2 = g2, g1 - q*g2 x1, x2 = x2, x1 - q*x2 y1, y2 = y2, y1 - q*y2 return g1, x1, y1 (Not that the above counts as a complicated algorithm, of course.) Mark