Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Value of a statement with modifier

by hossman (Prior)
on Jan 23, 2007 at 02:40 UTC ( [id://596023]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Value of a statement with modifier
in thread Value of a statement with modifier

There is no one right answer...

if you return an empty list to mean "false", the false-ish-ness could be lost (or other problems could arise) if your return value is "slurped" into another list context

...

There's no substite for extensively documenting that your method may not work the way people think and making it their responsibility to force the calling context.

  • Comment on Re^3: Value of a statement with modifier

Replies are listed 'Best First'.
Re^4: Value of a statement with modifier
by diotalevi (Canon) on Jan 23, 2007 at 07:21 UTC

    Returning undef for false is more broken than returning empty lists for false. At least an empty list is easily promoted to a false or undef value but an undef value in a list is not as easily demoted to a false value. I think all the people returning undef for false are shortsighted and I hope they never get their hands on my code.

    sub empty {} if ( empty() ) { ... } # ok @foo = empty(); if ( @foo ) { ... } # ok sub returns_undef { undef } if ( returns_undef() ) { ... } # ok @foo = returns_undef(); if ( @foo ) { ... } # NOT OK if ( grep { defined } @foo ) { ... } # oh ok, now it's "better".

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

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

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

    No recent polls found