Saturday, August 25, 2012

Re-blogging my experience on this really cool blog.

The other day, I was going through some JDK code to understand what was happening under the hood. I saw this code in a couple of places. (such as binary search and merge sort) I really couldn't figure out why someone would want to use the unsigned right shift operator to do simple division.
mid = low + high >>> 1;
mid = low + high / 2
instead of this,

Until I recently came across this post from Peter Norvig in this blog Google Research Blog This bug must have been fixed by Josh Bloch I guess. Since he seems to be the author of the classes which I was checking.
A small side note here, I too fell into the trap of thinking this was done for performance issues. However the blog clearly states the root cause was something more sinister. Love to be in a place where your code get's pushed to the limit. I guess scale is an awesome beast to deal with.
When will my day arrive :-(. When millions use my code.

No comments:

Post a Comment