Notes IV

bearophile bearophileHUGS at lycos.com
Thu Jan 24 07:54:18 PST 2008


Oskar Linde:
> On a similar topic, here are two of my favorite bugs:

In ObjectPascal you often restrict numbers to an interval (like 1..20) to *avoid* certain bugs, so you often use an unsigned integer if you want to be sure a number is never negative. In D I do the opposite, I usually use signed numbers (but in the very uncommon situations I need to use the number as a bit sequence, and few other situations) because they seem a bit safer.

array.length being unsigned probably leads to some bugs, so maybe it's better to waste one bit (and reduce the max array length by half on 32 bit CPUs. half the range on 64 bit CPUs isn't a problem, I presume), using a signed integer, to increase code safety (there are another solutions to this problem, like improving the upcasting, or introducing integer overflow cheeks).

Bye,
bearophile



More information about the Digitalmars-d mailing list