Signed word lengths and indexes
BCS
none at anon.com
Tue Jun 15 07:34:21 PDT 2010
Hello Steven,
> On Tue, 15 Jun 2010 07:30:52 -0400, bearophile
> <bearophileHUGS at lycos.com> wrote:
>
>> Steven Schveighoffer:
>>
>>> i is unsigned, and therefore can never be less than 0. It's
>>> actually a clever way to do it that I've never thought of.
>>>
>> Clever code is bad. It must be minimized. In some rare situations it
>> becomes useful, but its usage must be seen as a failure of the
>> programmer, that was unable to write not-clever code that does the
>> same things.
>>
> Clever code is bad? What are you smoking? In my opinion, clever code
> that is clear and concise should always be favored over code that is
> unnecessarily verbose.
Cleaver in my book normally equates to: requiters extra thought to create
and read. The exact opposite of clever is not dumb, but simple: with very
un-clever code the reader is I/O bound, they can understand as fast as they
can read it.
>
> In this particular instance, the code is both clear and concise.
That code might be concise but it is not clear.
>
> The following line of code should generate the exact same code, but is
> more verbose:
>
> for(uint i = end - 1; i < length && i >= 0; --i)
That code is just as bad IMO and for exactly the same reason: you are counting
on underflow and wrapping to make a i<j test start failing after i decrease.
>
> The compiler will throw away the second check during optimization,
> because i is always >= 0. I don't see why such code should be
> preferred.
>
> -Steve
>
--
... <IXOYE><
More information about the Digitalmars-d
mailing list