Case Range Statement ..

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jul 11 11:08:59 PDT 2009


Lutger wrote:
> Daniel Keep wrote:
> 
>> Valery wrote:
>>> I think that inclusive ranges more intuitive for beginner programmers
>>> because statements:
>>>
>>>   case 1..10,
>>>   array [1..10],
>>>   foreach (int item; 1..10),
>>>   foreach_reverse (int item; 1..10) (now foreach_reverse range is too
>>>   dificult to understand it: item begins with 10 or 9, ends 1 or 2?)
>>>
>>> will not require an explanation of their actions. Thanks.
>> I can say from personal experience that this is true.
>>
>> 1-based indexing is also easier for beginners.
>>
>> So are BASIC and LOGO.
>>
>> You may notice a trend here... :P
>>
>> Inclusive ranges are easier for naive programmers to grok, but are
>> fundamentally mismatched to programming.  It's harder to split an
>> inclusive range, and it complicates the math.  Just try writing anything
>> which involves manipulating ranges in Lua; it's considerably harder than
>> with exclusive ranges.
>>
>> The question is which you would rather: help naive programmers work
>> inefficiently or prevent competent programmers from working efficiently?
>>
>> I say screw the beginners; learning will do them good.
> 
> Besides, when learning programming the concept of zero-based indexing and 
> exclusive ranges is amongst the most trivial of concerns you need worry 
> about these days.
> 

On the other hand indeed foreach_reverse is tricky and I bet it does the 
wrong thing with floats. Actually let's see:

import std.stdio;

void main()
{
     foreach_reverse (i; 0.7 .. 100.7)
     {
         write(i, " ");
     }
}

The last number printed is -0.3. I think this has been discussed, but I 
can't find a bugzilla about it.


Andrei



More information about the Digitalmars-d mailing list