I love assert

Ian Kelly ian.g.kelly at gmail.com
Fri Nov 14 11:40:16 EST 2014


On Fri, Nov 14, 2014 at 4:37 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Ethan Furman wrote:
>
>>> There's no way to make the CONFUSED status be handled without actually
>>> changing the code. The difference is that this version will not
>>> incorrectly treat CONFUSED as WARNING; it just won't do anything at
>>> all if the code is optimized.
>>
>> So, a different wrong thing, but still a wrong thing.  ;)
>
> And potentially a *worse* wrong thing.

Potentially it's worse, but more likely doing the wrong thing will be
worse than doing nothing.

>    "I find it amusing when novice programmers believe their main
>     job is preventing programs from crashing. ... More experienced
>     programmers realize that correct code is great, code that
>     crashes could use improvement, but incorrect code that doesn’t
>     crash is a horrible nightmare."
>     -- Chris Smith
>
> Assertions can help by this, by causing wrong code to fail as soon as
> possible (provided, of course, that you don't defeat the assertions by
> running the code with assertions disabled).

I fail to see the relevance of this quote. The code I posted that
you're responding to does use an assertion. The case where it does "a
different wrong thing" is precisely the case where assertions are
disabled.



More information about the Python-list mailing list