Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>: > Marko Rauhamaa wrote: > >> Asserts are not about notification, checking or optimization. They are >> about communicating what's going on in the programmer's mind. They are >> comments. > > Assertions can be used for *all of these things*. > > Assertions can be used for: > > - checking internal program logic; > - testing pre- and post-conditions; > - testing program invariants; > - comments which are verified at runtime;
Most importantly, assertion failures are not supposed to be recovered from (within the program). Assertion failures can result in the loss of life and limb. They can result in database corruption. They can result in monetary losses. They can result in smoke coming out of the monitor. That's because the programmer is in no way prepared for the assertion to fail and cannot rely on the assertions to really be checked. IOW, assertions are not a mechanism for fault-tolerant programming. Marko -- https://mail.python.org/mailman/listinfo/python-list