Time to move std.experimental.checkedint to std.checkedint ?
tsbockman
thomas.bockman at gmail.com
Sat Mar 27 22:29:13 UTC 2021
On Saturday, 27 March 2021 at 21:02:39 UTC, jmh530 wrote:
> Are you familiar with how Zig handles overflow [1]? They error
> on overflow by default, but they have additional functions and
> operators to handle when you want to do wraparound.
Thanks for the link; I hadn't seen Zig's take before. It agrees
with my conclusions from developing checkedint: assume the user
wants normal integer math by default, signal an error somehow
when it fails, and wrap overflow only when this is explicitly
requested.
It's not just about reliability vs. performance, it is about
making the intended semantics of the code clear:
0) Is overflow wrapped on purpose?
1) Did the programmer somehow prove that overflow cannot occur
for all valid inputs?
2) Was the programmer desperate enough for speed to knowingly
write incorrect code?
3) Was the programmer simply ignorant or forgetful of this
problem?
4) Did the programmer willfully ignore overflow because it is
"not the cause of enough problems to be that concerning"?
Most code written in C/D/etc. leaves the answer to this question
a mystery for the reader to puzzle out. In contrast, code written
using a system like Zig's is far less likely to confuse or
mislead the reader.
> Nevertheless, I agree that the ship has sailed for D2 on this.
Yes.
> [1] https://ziglang.org/documentation/master/#Integer-Overflow
More information about the Digitalmars-d
mailing list