Linq and the like

Michiel Helvensteijn nomail at please.com
Sun Feb 3 05:25:48 PST 2008


bearophile wrote:

> LINQ (and its future parallel extensions), with its additional syntax, may
> be a good thing to add to D:
>
http://www.moserware.com/2008/02/for-loops-using-i-i-enumerators-or-none.html
> 
> You can use the same syntax to simplify parallel code, DB access code,
> etc.

Can't D already do this?

It has lazy evaluation of function literals, so the container class just has
to implement the count method.

Even C++ can do this, though it looks more messy.

Anyway, I disagree with the author about (at least) two things.

* I am one of those people that use the pre-increment operator in for-loops.
I know it doesn't improve performance for integers, but it does for
iterators. So I just use it everywhere for consistency.

* While I agree that when a foreach-loop is possible, you should use it, it
can never completely replace the for-loop, because it is simply less
powerful. Any number of sorting/searching algorithms still need for-loops.

-- 
Michiel




More information about the Digitalmars-d mailing list