Super-dee-duper D features
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Tue Feb 13 22:54:52 PST 2007
janderson wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> renoX wrote:
>>> Andrei Alexandrescu (See Website For Email) a écrit :
>>>> James Dennett wrote:
>>>>> C++, of course, has std::for_each(e.begin(), e.end(), do_x);
>>>>> in its library (though that's weaker than it could be because
>>>>> of lack of support for convenient anonymous functions/lambdas).
>>>>>
>>>>> C++0x is very likely to have for(v: e). It's implemented
>>>>> in ConceptGCC already. Java already has essentially that,
>>>>> as does C#. This really doesn't set D apart (but at least
>>>>> D isn't falling behind here).
>>>>
>>>> BTW, D might soon have simultaneous iteration that will blow away
>>>> all conventional languages:
>>>>
>>>> foreach (i ; coll1) (j ; coll2)
>>>> {
>>>> ... use i and j ...
>>>> }
>>>> continue foreach (i)
>>>> {
>>>> ... coll2 finished; use i ...
>>>> }
>>>> continue foreach (j)
>>>> {
>>>> ... coll1 finished; use j ...
>>>> }
>>>>
>>>> Best languages out there are at best ho-hum when it comes about
>>>> iterating through simultaneous streams. Most lose their elegant
>>>> iteration statement entirely and come with something that looks like
>>>> an old hooker early in the morning.
>>>
>>> At first, I really didn't like the 'continue foreach', then
>>> afterwards I got used to it, I wonder if this is really such a
>>> requested feature though, what's wrong with the good old 'for' or
>>> 'while' for the complex case?
>>
>> Absolutely nothing's wrong. The same argument, however, could be
>> formulated to render foreach redundant. We have for, don't we.
>>
>> The thing is foreach is terse and elegant and has a functional flavor
>> that gives it safety and power that for doesn't have. It's only
>> natural to ask oneself why all of these advantages must go away in a
>> blink just because you want to iterate two things simultaneously.
>>
>>
>> Andrei
>
> I think its about how much this feature will be used. This one seems
> like it could be useful but its pretty close to borderline-"feature for
> feature sake" for me. There are probably a lot of other features that
> could be more useful then this one.
No doubt, but there are many factors to take into account (among which
implementation difficulty). In Perl it's a constant source of friction
for me. If I want to iterate through one thing (array, file, hash...),
it's all dandy. As soon as I need to iterate over two things I need to
import and use an arcane library, or fall back and use while(1) and do
it all with the axe (which is what I end up doing most of the time).
I'm actually mildly surprised. Lately there was some talk around here
about supporting the day-to-day programmers and so on. I find looping a
very day-to-day thing, and looping over 2+ things at least a
few-days-to-few-days thing. There is a need for parallel iteration, if
nothing else shown by the existence of a library that addresses exactly
that - to the extent possible in a library that's not in the position to
control syntax, scoping, and visibility. I was sure people will be on
this one like white on rice. But Bjarne Stroustrup was right: nobody
knows what most programmers do :o).
Andrei
More information about the Digitalmars-d
mailing list