Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Think for yourself.

by Abigail-II (Bishop)
on Oct 07, 2003 at 09:39 UTC ( #297241=note: print w/ replies, xml ) Need Help??


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

While I have no trouble understanding a map in void context, using a map for its side-effects violates my expectations of what map is for.

I think this is the main point where you and I differ. What makes "map" so holy that it shouldn't be used for side-effects? Who or what started this notion? Not Larry, otherwise he wouldn't have made $_ an alias for the list element being processed. Many functions in Perl have side-effects, both user defined and core functions. Why is it fine to have side-effects in a 'for', but not in a 'map'? It's not that 'map' is called 'apply_a_function_and_return_a_list_of_calculated_values'. 'map' just means 'map a function over a list' - and I've been familiar with both the name and its function longer than Perl exists.

Abigail


Comment on Re: Think for yourself.
Re: Re: Think for yourself.
by tilly (Archbishop) on Oct 08, 2003 at 02:43 UTC
    This is a good question. And I don't know the answer.

    I can try to answer where I picked up the notion though. I first saw map and grep actually used in a bad CGI book (whose title I have forgotten), where the author was trying to tell people to write loops like that. I thought the advice was silly, and it didn't take long before I learned enough to realize that the book was bad. Furthermore I noticed that people who were far more experienced than I sometimes criticized people for using map and grep for side-effects, and I filed that away as another fault of the book.

    When I later saw map and grep being used more appropriately, it was in the context of side-effect free transformations. Not long after that I ran across them in some material that I was reading about Lisp, and about functional languages, which advocated making functions side-effect free for a variety of reasons (mainly more transparent modularity and easier debugging). I took the notion back to my Perl, and began using map and grep fairly consistently, but always with side-effect free blocks.

    This stylistic choice became a habit, and the habit became an expectation, and that continued with rather little thought about the matter on my part until this week.

    So I guess that the answer is that the people who chanted against map and grep in void context set my original notions, and then the notion that it was good to actively avoid having them have side-effects came for me from other languages that I was trying to learn about.

    I doubt that many other Perl programmers who hold my opinion hold it for the same reason though.

Re: Re: Think for yourself.
by zby (Vicar) on Oct 08, 2003 at 10:27 UTC
    People often call "map" and "grep" functional programming techniques. Since in pure functional programming there are not side effects, this may explain why some people (including me) don't expect side effects in them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://297241]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-12-27 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls