3 ms·
>why do you care about the runtime cost of something that makes your program crash ? I think both parent commenters (htfy96 and Asooka) got on a tangent becaus
by jasode 8y ago
>why do you care about the runtime cost of something that makes your program crash ?
I think both parent commenters (htfy96 and Asooka) got on a tangent because htfy96 substituted a throw exception for an assert() in gp's (hermitdev) code -- as if they were equivalent. However, exceptions have fundamentally different semantics from asserts and are not substitutes for each other. (For anyone unfamiliar with the different purposes of exceptions vs asserts, please read the top 2 answers in this Stackoverflow question.[0])
Things like array bounds checking (used as a runtime safety check instead of an "impossibility" check) would not be tested with assert().
To answer your direct question, programmers who use assert() correctly for "testing their understanding of the world by testing an impossible condition" don't want to pay a runtime penalty for it.
[0] https://stackoverflow.com/questions/1467568/debug-assert-vs-exception-throwing/1468385 https://stackoverflow.com/questions/1467568/debug-assert-vs-...