Re:Solutions to Integer Overflow
by dbaupp on Saturday September 03, 2016 @04:01AM
(#12418248)
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.
[ Parent
| on HN ]
Re:Solutions to Integer Overflow
by SamReidHughes on Saturday September 03, 2016 @04:49AM
(#12418376)
Swift has release-mode assertions, they're done with precondition().
You 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.