Mismatch between assert's semantics and how it's used (-O, -OO, disable)

I think a disconnect in this thread is the intuition about the current state of code. Those who support this change think that yes indeed, the vast majority of assertions are currently “buggy”, in that the statements were intended to always execute and the author wasn’t thinking (or didn’t know) about -O.

Whether this is even “buggy” feels a bit nebulous to me. One answer is “this code wasn’t written for running under -O” and another answer is “it runs fine, but you might see other problems when not guarded by the assertions”. I can’t imagine code that actually needs assertions to go off for it to function properly [1].

An alternate proposal in the old thread was to go the other way: turn off assertions by default and add them to -X dev, so that people using assertions incorrectly have to change, rather than whatever unknown % were doing things right the whole time. I think that makes sense, and I count myself among those who were Doing it Wrong™ [2].


  1. but I’m sure some cursed library is doing it somewhere ↩︎

  2. not that I have ever run python with -O in my life ↩︎

2 Likes