Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

February 27, 2004

Proper Numerical Data Types

Simon points to the 2nd edition of Code Complete which I had a quick look at and ended up downloading Chapter 12 on "Fundamental Data Types"

Which reminded me of a little pet hate I have been meaning to mention for a while now - the endless varieties of numerical data types I'm forced to deal with.

I'm an application developer, why should I care if it's a long int, a short integer, a float, a double or a 99 with a Cadbury's flake? I just want to input, store and display a number. I want to be sure that what I put in I get out, and that is it. Inappropriately sized number variables (and database columns) are the bane of my life and cause more boundary errors than problems they solve. I'm not even sure that specifying a variable as a short integer rather than plain integer solves any problems anyway.

Likewise in my database I want to be able to say that my column contains numbers. If there is a limit, such as a specific range or set of values, I can enforce it with a constraint. I don't care how the actual values are stored on disk, that is what the database engine is for. In a program I can enforce the rules with my accessor methods. But in the vast majority of cases I just don't care.

The different types of numerical data types that are present in modern programming languages like Java and databases like DB2 UDB are a throwback to times when resources were scarce and we, the application programmers, had to worry about every spare byte.

Well, these days my laptop has a gigabyte of memory and a sixty gigabyte hard drive so I really just don't care. Saving a few pennies now on storage can cost a lot more in the future. For instance a company of my acquaintance is now spending two person years of effort to enable their order management system to support eight digit product identifiers rather the six digit ones they currently use. The hardware cost to support this project is roughly the equivalent of one desktop PC. Had they had the ability to specify them as numbers they would have saved the development effort, but still had to fork out for the extra disk space.

All of which is just my Friday afternoon whinge, as well as a thank you to higher level languages like Python which get it right - most of the time.

Posted by Andy Todd at February 27, 2004 04:10 PM


Sadly, programmers will need to be aware of some differences for quite some time. For example (3 - 2) == 1, but (3.0 - 2.0) is not necessarily 1.0, even in languages that don't make you explicitly declare types.

Posted by: Alan Green on March 1, 2004 03:48 AM