4 ms·
Ideally I'd like a compile-time error — but that's beyond the current level of technology, so the next best thing is a crash. Having code that does unintended t
by chc 7y ago
Ideally I'd like a compile-time error — but that's beyond the current level of technology, so the next best thing is a crash. Having code that does unintended things is the worst-case scenario IMO. (Obviously it's the programmer's fault for providing buggy code, but that's a fault that every programmer shares. Personally, I appreciate any help in guarding against it.)
- jiofih 7y ago> beyond the current level of technology I’m sure there quite a few languages that will catch that at compile time.
- earenndil 7y agoIt is possible for a compiler to catch that particular mistake at compile-time. It's also possible for the user to provide a proof to a given compiler that a comparison function is well-formed. But I think that the parent was referring to a function that would check arbitrary comparison functions in java for correctness, without a proof, which is afaik provable impossible.
- estebank 7y ago> but that's beyond the current level of technology Is it? In Rust and other languages you would use trait bounds to restrict the input types to be comparable with each other, which would make this a compile time error.
- Dylan16807 7y agoHow does that prevent you from accidentally making a.compare(b) and b.compare(a) inconsistent on some values? Making sure you can compare the types is already happening in the compiler, and doesn't find the bug.