Re: [boost] Re: Re: Re: Formal Review: FOREACH macro

In-Reply-To: <d55r5q$9h2$1@sea.gmane.org> gennadiy.rozental@thomson.com (Gennadiy Rozental) wrote (abridged):
Adding #defines is adding complexity.
I think it's a kinda an attitude issue: you see all macros as enemies.
No. Adding almost anything is adding complexity. It's another layer. And of course a rather powerful layer - a macro can do almost anything. Also you snipped the context. Your proposal here was, if I understand correctly, to use conditional compilation to switch off FOREACH's support for corner cases. So we are adding more options and configurability, and the potential for my corner cases not to work because support for them has somehow been switched off (where - in the makefile?). Even if I know how FOREACH works in my project, it might work differently on my colleague's project. And I have yet more code to read when I look at the header. It's as if we were trying to build the most complex thing that could possibly work.
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. -- Dave Harris, Nottingham, UK.

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
participants (2)
-
Andrei Alexandrescu (See Website For Email)
-
brangdon@cix.compulink.co.uk