Hacker News new | ask | show | jobs
by sullyj3 3273 days ago
I can't tell if this is satirical, but to be clear, you're proposing to disallow addition?
2 comments

You could test whether overflow is going to happen first. Or use a math library that explicitly overflows with predictable results.
I know very few languages that do that. Even Rust doesn't when compiled for release. All for performance reasons.
Some additional points:

* It's not UB in Rust, it's guaranteed to be two's compliment overflow.

* It's still a "program error" and debug builds are required to panic.

* Non-debug builds are allowed to either panic or do the overflow, for performance reasons, as you mention. If it was feasible to always panic we'd do that; the current wording allows us to change it to do so in the future if it becomes feasible.

* If you want to do a checked add, you can, it's just not the default.

I might have lost the point in this long thread, but I'm pretty sure the suggestion was just to add it as an optional flag.
Rather define the behaviour of what happens when addition of two ints exceed the maximum allowed value.
You're changing your plan here. Maybe you could at least concede that the issue of UB is difficult and is not going to be solved by saying "why don't they just" on HN?