Archive for November, 2007

Whatever Happened to the “Old School” Programmers?

Monday, November 26th, 2007

Uh, oh. I think I’m way too young to sound like such a curmudgeon, but I just can’t help myself. Before my recent move to a post-sales role, I spent 15 years writing software professionally. I thought at this point in my career I’d qualify as “the wise elder” – instead, I guess I’m just “the crazy old man who mumbles to himself.”

Remember the days of eagerly poring over core dumps to quash that nasty bug? The fascination of learning something new? The determination to write code properly so it could be maintained and easily understood by others? Remember when “so what? it works” just wouldn’t cut it for maintainable design?

I loved it. So, what is it with kids these days?

(more…)

Java, GPS Receivers, and Geocaching: Vincenty’s Formula

Friday, November 16th, 2007

Vincenty’s Formula is an iterative solution for calculating the distance and direction between two points along the surface of Earth. For clarity, I’ve stripped out portions of the code I’ve put up for discussion, but you can download the entire Java source code from here. If you prefer C#, please see the C# version of this discussion.

Several years ago, I stumbled on a great pastime called “geocaching.” It’s a worldwide treasure hunting game where participants use handheld GPS receivers to find hidden “caches” – small boxes filled with prizes, trinkets, and “travel bugs“. The caches are hidden by other participants who post nothing more than the latitude and longitude on a website like Geocaching.com. My children and I have had a blast. It’s a great way for a grown man to justify playing in the woods (and buying an expensive gadget!) under the pretense of “playing with the kids.” With over 420,000 caches in 222 countries on all continents (including Antarctica!) there are bound to be several near you.

(more…)

C# Decimal and Java BigDecimal Solve Roundoff Problems

Tuesday, November 6th, 2007

Roundoff problems have been the bane of programmers since computers started handling floating point numbers. Floating point numbers are represented by a finite number of bytes. This limits the precision of numbers that may be represented – you only get so many significant digits. More subtly, however, finite length floating point numbers limit which numbers may be represented accurately. Repeating decimals (which, in a sense, require an infinite number of significant digits) cannot be represented precisely. You may only store the nearest value representable by the computer. This is the origin of annoying roundoff problems found in floating point arithmetic.

The C# and Java 4-byte float data type provides 7 significant digits of precision, while the 8-byte double type provides 15. Using the higher precision double data type helps minimize the roundoff error, but it must still be addressed.

So, when I encountered the C# 12-byte decimal data type with its 28 significant digits, and Java’s arbitrary size BigDecimal data type, I figured these were simply ways of further minimizing the problem with a wider floating point type. Only after digging deeper did I realize that the implementation behind both of these data types is a stroke of genius.

(more…)