On Fri, Nov 01, 2002 at 03:10:54AM -0500, Perrin Harkins wrote:
> There is a time and place for map: when you want to do something
> to each element in an array and return the array on the other side.
> Otherwise, use for, like this: some_function($_) for @array;.

> Even when map is not incorrect, I usually avoid it because it has a 
> tendency to take your code from nice, readable perl to evil h@x0r PERL 
> in 3 characters.  This is the kind of thing that Yahoo was probably 
> worried about when the decided not to use Perl.

This statement surprises me somewhat.

It sounds like you're saying that you should only use a subset of Perl
as some programmers may not understand the other parts of it?

I'd say that if this were true the problem is in training the programmers.
map and grep are very powerful constructs, and when used correctly lead
to much more readable and maintainable code once you understand them:

Given:
  sub square { $_[0] ** 2 }
  my @nums = (1 .. 10);

Which would say is more readable and maintainable?

1)
  my @squares;
  push @squares, square($_) for @nums;

2)
  my @squares = @nums;
  $_ = square($_) for @squares;

3)
  my @squares = map square($_), @nums;

I'd go for (3) every time.

Tony

Reply via email to