On 9/11/07, Palit, Nilanjan <[EMAIL PROTECTED]> wrote: [...] > > It is very bad form to use map as a looping construct. > > Can you elaborate why it is a bad form: readability, performance, ...? > Just want to understand the underlying reason. (To me, both the for & > map inline forms appear to be the same readability & performance wise.)
Readability is the big difference. The difference between map and for is that map is _supposed_ to construct a return list. (In recent versions of Perl it actually doesn't construct one in void context, but that is a technical detail.) Therefore choosing to use map rather than for is a strong hint that the return list is going to be used somewhere. When it is not going to be used, you have just mislead experienced programmers. The other is understandable, but it is poor form. Like someone with bad English, you can be understood, but the listener also understands that you don't know English very well. Furthermore you're demanding more from your readers than you need to. Anyone who speaks English (or who knows a couple of computer languages) can guess what a for loop does. But only people who know Perl will understand what map does. A more subtle consideration is that good programmers actively try to avoid side effects. If you get used to this style, then you deliberately try to write code which doesn't depend on side effects. >From these programmers, map not only has an implicit promise that the return list will be used, but also has one that the map block won't have side effects. And, of course, you've broken that promise. These costs may seem to be small, but they are real and there is no corresponding benefit to using map in the way that you did. So why use map? And as insignificant as this may seem, good programmers try to accumulate lots of small benefits like that. While the individual wins are small, the cumulative effect is quite significant. For more discussions, with points pro and con, see http://www.perlmonks.org/?node_id=296795. Cheers, Ben _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

