Signed word lengths and indexes

BCS none at anon.com
Tue Jun 15 08:39:43 PDT 2010


Hello Steven,

> On Tue, 15 Jun 2010 10:34:21 -0400, BCS <none at anon.com> wrote:
> 
>> 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.
>> 
> Clever code does not have to be hard to understand.  In this case,
> it's  not hard to understand.  You admit yourself that you understood
> it within  a second ;)
> 

Yup, and a second is several times to long for code that accomplishes something 
that simple.

>>> In this particular instance, the code is both clear and concise.
>>> 
>> That code might be concise but it is not clear.
>> 
> Since uint is declared inside the loop statement, I'd say it is clear
> --  it's not open to misinterpretation.  If i was defined elsewhere,
> I'd agree.

That i is a uint is clear, but any code that depends on underflow is IMO 
not clear as it requiters thinking in a (for most people) less than intuitive 
way.

> if you understand the rules

Other forms avoid that requirement. The fewer constraints/requirements you 
place on the reader of code the better.

I think the difference of opinion here stems from you basing your assessment 
on what is required of the (single) person who writes the code where as I'm 
basing my assessment on what is required of the (open set of) people who 
read the code.

-- 
... <IXOYE><





More information about the Digitalmars-d mailing list