Google Points Out Lurking Bug
Joshua Bloch has posted on the Official Research Blog about how most binary search and merge sort code is broken and has been for years.
The bug is to do with large arrays, and highlights how often programmers accept code that will do “for the examples we have right now” rather than considering whether it’ll work “in every situation where a future programmer might expect it to work”. It’s great to re-use code, but make sure it is re-usable beyond toy examples!
Joshua’s article is well worth a read.
2 Comments
Please use the DP Forums for further discussion of this topic.



That’s nothing to do with sorting, though, and absolutely nothing to do with mergesort…
It’s just a standard “fixed length ints are not integers” problem.
Jiri
Comment by jiri — On 4-6-2006 at 4:30:52 PM
it’s like asking
(1.0/3.0 + 1.0/3.0 + 1.0/3.0) // is this equal to 1.0 exactly?
no bitwise for google….:-(
Comment by joako — On 1-5-2007 at 1:49:30 PM