Site Archive (Complete)
C++ Blog: The abstraction quality dilemma
C++
void main(void)

Calls, Returns and In-Between.

by Kevin Carlson
SELECTIVE IGNORANCE

Finding the Signal in the Noise

by Andrew Koenig
October 13, 2006

The abstraction quality dilemma

Library authors often face a tough choice: Is it worth the extra effort to get obscure cases right that may never be needed?

For example, if m and n are int variables, then m+n is the sum of the values of m and n whenever that sum can be represented as an int. However, if we introduce a third variable into the picture, say k, then we find that k+m+n might be undefined even though the mathematical sum fits in an int. For example, k+m might overflow, but n might be negative.

Now imagine that you are writing a library function to compute the sum of three integers. How would you go about it? Would you bother getting the edge cases right? What would you do if a user of your library function complained that it was failing to get the right answer in some circumstances?

Library authors use abstractions in order to provide abstractions to their users. Ideally, the abstractions they provide should be as robust as the ones they user. In practice, though, such a state of affairs is sometimes hard to achieve.

Posted by Andrew Koenig at 08:04 AM  Permalink




 
INFO-LINK


Related Sites: DotNetJunkies, SD Expo, SqlJunkies