On 21/04/2011 15:51, Peter Duniho wrote:
> On 4/21/11 7:36 AM, Marcel Müller wrote:
>> [...]
>>> p1 should compare as less than p2, but the "clever" approach will
>>> claim that p2 is greater than.
>>
>> the OP used floting point values (PointF). So this will not happen.
>
> Ah, yes. Should have looked more closely. Thanks.
>
> Even so, other bad things can happen with overflowed values (such as the
> exception you mentioned…not sure why I didn't put 2 and 2 together
> there; tunnel-vision, I guess).
>
> Subtractions aren't comparisons; they should only be used as such if
> there is both a VERY good reason for doing so (e.g. the values have to
> be subtracted anyway and performance is for some reason _critical_),
> _and_ one can guarantee the values stay within a small range that
> guarantees the result of the subtraction remains valid for comparison
> purposes.
>
> It is exceedingly rare for both of those conditions to hold. Heck, the
> first condition alone is exceedingly rare.
>
> Even ignoring the correctness issue, the other big problem with being
> "clever" like that is that it makes the code much harder to understand.
> If you write a comparison, it's obvious you're comparing things. If you
> try to implement a comparison using something other than a comparison,
> now every time someone looks at that code, they have to figure out
> whether the "other than a comparison" code is actually performing a
> comparison.
>
> Just say "no". 
>
> Pete
Thanks guys for the input. I'm new to c# and didn't even know there was
a CompareTo.
Not so sure of your 'cleverness' jibe though.