←back to thread

611 points LorenDB | 3 comments | | HN request time: 0s | source
Show context
codedokode ◴[] No.43908897[source]
What about catching integer overflow? Free open-source languages still cannot do it unlike they commercial competitors like Swift?
replies(5): >>43908922 #>>43909326 #>>43909444 #>>43910683 #>>43912986 #
lytedev ◴[] No.43908922[source]
I'm not sure if this is what you mean, exactly, but Rust indeed catches this at compile time.

https://play.rust-lang.org/?version=stable&mode=debug&editio... https://play.rust-lang.org/?version=stable&mode=debug&editio...

replies(1): >>43909313 #
codedokode ◴[] No.43909313[source]
I meant panic if during any addition (including in runtime) an overflow occurs.
replies(3): >>43909686 #>>43909733 #>>43913823 #
1. tialaramex ◴[] No.43913823{3}[source]
Why do you want a panic? Shift left. Overflow can be rejected at compile time for a price that you might be able to afford - generality.

Just insist that the programmer prove that overflow can't occur, and reject programs where the programmer couldn't or wouldn't do this.

replies(2): >>43918680 #>>43918718 #
2. ◴[] No.43918680[source]
3. codedokode ◴[] No.43918718[source]
Programmer has other things to do. Computer or CPU should do the checks.