Another foreach idea.

Fredrik Olsson peylow at gmail.com
Tue Jun 13 10:44:26 PDT 2006


Dave skrev:
> Kirk McDonald wrote:
> 
>> Dave wrote:
>>
<snip>
>> Though honestly, a regular for loop isn't much of a burden.
>>
> 
> You're right, it isn't, until you run into some time critical loops that 
> you'd like to leave to the compiler to optimize. And a loop-invariant 
> condition and 'range' could allow foreach to better do things like loop 
> unrolling or use vector instructions, I think. It'd be one more thing 
> that sets D apart too.
> 

I can take this as an opportunity to yet again voice my opinion for 
implementing ranges and sets as basic types of D. Templates are good and 
all, but as Walter writes himself on proper handling of floating point 
and infinity:
1. Building it in to the core language means the core language knows 
what a floating point infinity is. Being layered in templates, typedefs, 
casts, const bit patterns, etc., it doesn't know what it is, and is 
unlikely to give sensible error messages if misused.
2. A side effect of (1) is it is unlikely to be able to use it 
effectively in constant folding and other optimizations.

I think the same thing goes for ranges, ranged integer types and sets. 
The expressive power and the productivity boost they give is just too 
huge to be ignored. More work done with less code is _always_ good, less 
code == less bugs to avoid, find, and correct.

// Fredrik Olsson



More information about the Digitalmars-d mailing list