3 ms·
> It is nothing more than a language design mistake. Well, Ada[0] had ranged integer types which allowed the compiler to determine whether overflow can occur s
by nly 12y ago
> It is nothing more than a language design mistake.
Well, Ada[0] had ranged integer types which allowed the compiler to determine whether overflow can occur statically. I don't know why modern languages like C#, Java, Go and Rust don't do this instead of taking the performance hit... in general no JIT will save you, and it's useful for things like formatted I/O and parsing as well
[0] https://en.wikipedia.org/wiki/Ada_%28programming_language%29#Data_types https://en.wikipedia.org/wiki/Ada_%28programming_language%29...
- danbruc 12y agoInteroperability may be a factor. Everything that enters your world will tell you nothing about the possible ranges and you pretty quickly have to assume the worst case everywhere or add range limiting assertion early. It still sounds like a good idea but maybe it's harder to do than it seems.
- eric_bullington 12y agoI'm pretty sure Ada's ranged integer is tested dynamically, not statically. It's still a cool language feature. To get a static detection of integer overflow, I think that you need to use some variation of dependent typing. So it's possible in Liquid Haskell. And of course, it's easily done in dependent-typed languages like Agda, Coq, and Idris. Edit: I had earlier written Nim has this static range checking capability, but it looks like it also uses a runtime check.