Geek: integer overflow checking... This morning I ran across this short article that describes how to implement integer overflow checking in languages that don't expose the underlying hardware's overflow flag. Java is such a programming language, and CERT has a fine implementation of routines that provide the check.
I've long been surprised that Java doesn't include such checks, at the very least as options. In general Java tries very hard to be “safe” (for example, with array bounds checking and stack overflow checking) – but not on something as common and pernicious as integer overflow. It's a mystery to me.
Probably because of my “upbringing” on computer hardware and assembly language programming, I've always been very conscious of the possibility of integer overflow in my own code. Despite that, I've been burned by it several times, most especially with numeric comparisons (which I've blogged about before).
Just a few weeks ago, a colleague from a job I had almost 15 years ago contacted me out of the blue. This fellow happens to be Russian, and worked with me on Java code back then. He asked me if I'd ever heard of “integer underflow”, and if I could explain it to him. I could, of course, and I did. But once again I was shocked to discover that a well-educated, experienced, and superbly competent software engineer didn't know about something so basic. I engaged him in an email conversation about it, and I think I know now how such a thing happened: his education in computer science assumed the presence of a high-level programming language, and he only learned how computers actually work in broad, abstract brush strokes. Once again, what surprises me the most about this is just how productive a software engineer can be with such a (to me) gaping hole in his knowledge...
No comments:
Post a Comment