3 ms·
Many (maybe most) languages are OK with changing behaviour/code between debug and release builds, e.g. disabling `assert`s and even the optimisations themselves
by dbaupp 10y ago
Many (maybe most) languages are OK with changing behaviour/code between debug and release builds, e.g. disabling `assert`s and even the optimisations themselves. Of course, this is suboptimal in some cases, and thus providing a way to disable it is good and thus rustc has -C debug-assertions=on, and a currently-unstable flag to control just the overflow checks themselves. Seguing from that first flag, Rust makes it explicit when an assertion is OK to omit by providing both debug_assert! (removed in release) and assert! (never removed), so I guess Rust is in a middle ground that's the reverse of the middle ground of a language like, say, Swift, which removes assertions but not overflow checks in its default optimised build.
- SamReidHughes 10y agoSwift has release-mode assertions, they're done with precondition().
- dbaupp 10y agoYou are correct, but my point was implicitly that the default thing people reach for is assert, especially since the name precondition sounds like it is only ok to call at the start of a function.