|
Boost : |
From: Andrei Alexandrescu (See Website For Email) (SeeWebsiteForEmail_at_[hidden])
Date: 2005-05-02 23:43:08
>>I see some of them as friends. Macros in general (and FOREACH in
>>particular) are in most cases only usability helpers (there is also
>>configuration switched domain, but it's beside the point). And until
>>language provide as-convenient alternatives I am ready to accept the
>>macro nature of these tools.
>
>
> I'm ready to accept them too, when they do something worth while. This one
> doesn't.
Well, IYO :o). IMO it does. There are two things that give FOREACH an
advantage: (1) optional immutability of the value being iterated (and,
to my happiness, less syntax means more safety! yay!); (2) immutability
of the iterator itself.
Statistically---but please don't make me dig a reference to that one
:o)---most bugs are due to loops. The C for loop is the most general
loop; that's what also makes it the least structured. The fact that the
loop control sits in the header of the for statement is only a mere
convention, and, sadly, often an illusion to the beginner, unwary, or
maintainer :o). In contrast, FOREACH's header makes a much stronger
statement about the nature of the loop, and that brings structure. You
look at a line of code and you have some pretty good assurance about the
nature of the loop. That's where IMHO most of its value comes from.
Syntactic convenience is a good artifact, but it should be seen as not
much more than a fringe benefit.
Andrei
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk