Treating the abusive unsigned syndrome

Derek Parnell derek at psych.ward
Fri Nov 28 22:21:27 PST 2008


On Sat, 29 Nov 2008 01:17:27 +0100, Frits van Bommel wrote:


> Then it'd have different behavior from
> ----
>    auto diff = x.length - y.length;
>    if (diff < 100) ...
> ----
> 
> This seems like a *bad* thing...

I see the problem a little differently. To me, "x.length - y.length" is
ambiguous and thus meaningless. The ambiguity is are you after the
difference between two values or are you after the value required to add to
x.length to get to y.length? These are not necessarily the same thing.

The difference is always positive, as in the difference between the length
of X and length of Y is 4. The answer tells us the difference between two
lengths but not of course which is the smaller. So it all depends on what
you are trying to find out. And note that the difference is not a length
because it is not associated with any specific array. 

So having looked at it like this, I'm now inclined to consider that the
'diff' being declared here should be a signed type and, if possible, have
more bits than '.length'.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list