RFC on range design for D2

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 11 09:24:22 PDT 2008


"Bill Baxter" wrote
>> Thus one can implement iterators on top of ranges, but I'd argue that 
>> ranges
>> are much easier to implement on top of iterators.
>
> Ranges are safer and easier to work with in most cases so it's worth
> it, or so the argument goes.  You don't buy it?

I can define an iterator and it doesn't mean that it makes ranges any less 
safe.  Just give me the choice, if I think iterators are a better fit, I 
might choose iterators.  But having to shoehorn ranges into an iterator form 
so that I do not wince at the ugliness of my code seems like unnecessary 
baggage.

I believe that when you are actually using a range of values, a range form 
is a much better, safer fit.  When you want just a pointer to a single 
value, then a pointer-form is a better fit.  But I want to be able to 
construct ranges from pointers.  I want to save pointers.  I want to use 
pointers to refer to elements in a collection.  I want to use pointers to 
move one-at-a-time along a node-based container.  I don't want to 'emulate' 
pointers using ranges.  I don't want the library to resist me doing what I 
find natural.

This goes back to a lot of the points I've brought up about 'safety' issues 
in D.  D is a systems language, I like the safety by default, but when I can 
gain something by breaking the safety, I want to be able to do it 
efficiently, and without resistance from the compiler.  Like logical const. 
I've proven it's possible to emulate, but at a performance disadvantage. 
This is no different, you can emulate iterators, but at a performance (and 
code bloat) disadvantage.  Granted the disadvantage isn't as big for this as 
it is for logical const, but the question still remains - if I can do it 
already, why is it so bad if it's supported natively?

Anyways, I'm going to leave the discussion, I think I've said all I can 
about my views.  I'm not really good at explaining things anyways.  But I 
will update dcollections with what I think is the best compromise.  Then I 
might have a better understanding of how ranges fit into a collection 
package.  The good news is I don't have to worry about the language not 
providing iterators, everything is going to be library based, so we can 
easily try out both ways and see which is easier to use.

-Steve 




More information about the Digitalmars-d-announce mailing list