Assertions are bad, m'kay?
steve+comp.lang.python at pearwood.info
Fri Mar 7 12:11:49 CET 2014
On Fri, 07 Mar 2014 18:16:55 +1100, Chris Angelico wrote:
> They produce the wrong exception type, they disappear when you least
> expect them, and now we have another reason not to use assert.
> Abusing assert for arg checking violates XKCD 1339. Write
> standards-compliant code!
Assertions are not bad! They're just misunderstood and abused.
(By the way, assertions are not the same as assumptions. Asserts can be
used to check that assumptions are correct, or to check the internal
logic of your reasoning. Whereas assumptions are just accepted as if they
were correct, no questions asked.
You should read this guy's blog post on when to use assert:
It's pretty damn good, if I do say so myself...
More information about the Python-list