Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

What makes map so special?

Because its name and general usage strongly suggests that it should return something. Take a sub like get_value if you saw that in void context wouldn't you wonder what is going on? Wouldn't it annoy you to discover that in fact the routine has nothing to do with getting a value? Well likewise for me and map. If you want to do some action for each member of a list, then use foreach. If you want to transform each member of a list into something else and get the resulting list back, then use map. The cues in the name help you understand the intent of the author more quickly and with less effort. If someone plays silly bugger and uses map as for then they have just thrown away a useful cue to a future developer as to what was on their mind when they wrote the code.

Think about it for a minute. We do our best to not confuse ourselves and theose that come after us. We don't use $var1 and $var2 for our variable names so that the programmer that follows us (more often than not itll be ourselves a few days or weeks later :-) has a hope in hell of figuring out what it going on. We don't name our subroutines A, B, C etc, for similar reason. We dont use goto's as our primary flow control mechanism etc. All of these things are to provide as much of a cognitive model of what is happening as possible. The same goes for map.

I mean why make life hard? Perl has a hugely expansive vocabulary as far as programming goes. Why waste the expressiveness that it provides? Say what you mean and mean what you say. If you want to map a list then do so, if you want to iterate over the list then do so, but don't pretend to one when you are really doing the other.


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi



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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2014-08-21 08:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (128 votes), past polls