Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: Returning undef: The point I would like Damian to reconsider

by jdporter (Paladin)
on Jun 23, 2007 at 00:46 UTC ( [id://622931]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Returning undef: The point I would like Damian to reconsider
in thread Returning undef: The point I would like Damian to reconsider

WTF (that's "why") do you think I put "list" in quotes?

When I say "list", everyone (including you) understands what I'm talking about. Give it a rest.

More importantly, let's stick to the topic at hand. I intend to.

  • Comment on Re^4: Returning undef: The point I would like Damian to reconsider

Replies are listed 'Best First'.
Re^5: Returning undef: The point I would like Damian to reconsider ("list"?)
by tye (Sage) on Jun 23, 2007 at 01:02 UTC

    Well, I don't know about "everybody", but I get the impression that you are under the all-too-common but still mistaken impression that "arrays return their size in a scalar context while all lists return their last item in a scalar context".

    I was rather surprised and disappointed to see this flawed meme show up at PerlMonks several times recently, and from people who I expected to know better.

    But I guess that is what happens when we "give it rest" even after having trounced that myth repeatedly and in no small detail for so long. *shrug*

    - tye        

      I get the impression that you ... "... all lists return their last item in a scalar context"

      If I gave that impression, I certainly didn't intend to. I'm well aware that many "things we normally use in a list context" return an interesting variety of other things in scalar context. Note, I said that, imho, returning the last value when called in scalar context is the minimally surprising behavior. I can also see the validity of the opinion that returning the count (length) might be the minimally surprising behavior. Any behavior other than those two would, I believe, be entirely too surprising and should be avoided. Obviously, in any case, the behavior should be documented, particularly for public interfaces.

      ...what happens when we "give it rest" even after having trounced that myth repeatedly...

      You're talking about a different thing. What I'm suggesting that merlyn give a rest is a purely terminological argument.

      A word spoken in Mind will reach its own level, in the objective world, by its own weight
        then it should always return a "list", even in scalar context, i.e. if called in scalar context return the last value in its return expression.

        I don't know how to not interpret that as "being a 'list' means that it will return the last value in a scalar context". And I don't think the scare quotes make that more clear or less misleading. And using that with "always return" makes it more confusing to me.

        As for what is least surprising, I find that it depends completely on what the function does. Having scalar( caller()  ) be the same as ( caller )[-1] would make no sense and so would certainly be surprising. Returning the first item, returning a reference to an array, or returning a string that includes all of the items are three behaviors that I often find appropriate. Returning the last item is not something I choose often.

        - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-25 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found