Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re: Re: Re: Think for yourself.

by thelenm (Vicar)
on Oct 06, 2003 at 16:37 UTC ( #296990=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Think for yourself.
in thread is the use of map in a void context deprecated ?

I agree... the use of map in a void context also makes me look for how the return value is used, because to me, getting a return list is the main reason for using map. This type of distinction reminds me of the section in perlstyle that says:

Just because you CAN do something a particular way doesn't mean that you SHOULD do it that way. Perl is designed to give you several ways to do anything, so consider picking the most readable one. For instance

open(FOO,$foo) || die "Can't open $foo: $!";

is better than

die "Can't open $foo: $!" unless open(FOO,$foo);

because the second way hides the main point of the statement in a modifier. On the other hand

print "Starting analysis\n" if $verbose;

is better than

$verbose && print "Starting analysis\n";

because the main point isn't whether the user typed -v or not.

To me, using map in a void context seems like "hiding" the main point of the code. And I'll point that out to people, but there are much more flameworthy transgressions. :-)

-- Mike

XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
-- grantm, perldoc XML::Simpler

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Think for yourself.
by gwadej (Chaplain) on Oct 30, 2003 at 05:36 UTC

    Oops. I apparently did not make myself clear.

    I rarely use map or grep in a void context. When I said that I see map and grep and operations on a list. I mean it in much the same way that + is an operation on a number.

    When I need to transform a list into a new list, I tend to think of map. To me, the foreach approach focuses more on the individual elements of a list than on the list as a whole.

    That being said, I will break my own preferred approach any time it makes the code clearer.<grin/>

    G. Wade

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296990]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-05-25 13:51 GMT
Find Nodes?
    Voting Booth?