Revised RFC on range design for D2

bearophile bearophileHUGS at lycos.com
Tue Sep 16 13:48:31 PDT 2008


Andrei Alexandrescu:
> http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.html

I have re-read the page again, and I am now starting to understand its contents. When I'll understand 90-95% of that page then I think it's dumbed enough for most programmers ;-)

In lines like:
t=r.before(s)

I suggest to add a more natural spacing:
t = range.before(s)

But maybe adding an "all" to that method name you it can show better that it generates a new range:
t = range.allbefore(s)


This is one of the functions shown in that page:

// Increments all elements in a range
void bump(R)(R r)
{
    for (; !r.done; r.next)
    {
        ++r.head;
    }
}

But that's not readable. This improves readability 5X (note current instead of head and isdone instead of done):

/// Increments all items of a Forward range
void bump(R)(R range) {
    while (!range.isdone) {
        range.current++;
        range.next();
    }
}


If the D language will keep the foreach(), then where possible I suggest to add a version that uses foreach() too:

/// Increments all items of a Forward range
void bump(R)(R range) {
    foreach (ref item; range)
        item++;
}

In that document you can also show 1 example for all functions/ methods/ attributes, like r.after(s), etc.

I think that good names and some sugar may make this stuff usable (not easy, but usable).

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list