I love assert

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Nov 14 12:37:06 CET 2014


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.


   "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).



-- 
Steven




More information about the Python-list mailing list