Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Module Announcement: Perl-Critic-1.01 (just a scalar)

by jettero (Monsignor)
on Jan 26, 2007 at 22:11 UTC ( #596797=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Module Announcement: Perl-Critic-1.01 (just a scalar)
in thread Module Announcement: Perl-Critic-1.01

Why make (key => scalar &functionScalar) explicit, but not return undef;? That sounds like a matter of personal preference to me.

-Paul


Comment on Re^4: Module Announcement: Perl-Critic-1.01 (just a scalar)
Select or Download Code
Re^5: Module Announcement: Perl-Critic-1.01 (just a scalar)
by chromatic (Archbishop) on Jan 27, 2007 at 02:35 UTC

    Because it's the calling context that matters!

    Bare return; does the right thing in both scalar and list contexts. In my mind, that's a good thing.

    If you find yourself in an ambiguous situation, then you disambigate by being explicit. It would be nice if there were never ambiguous code, but that's not realistic.

      Bare return; does the right thing in both scalar and list contexts.

      I'm assuming that you are defining "the right thing" as "being false". For many functions, the "right thing" even in a list context is "return one scalar". Next we'll replace NaN with an empty list for the math functions.

      If you aren't assigning the list (return value), then the boolean nature of what is returned doesn't matter (well, if you are just checking the return value, then you aren't in a list context and return undef; works fine). Do you find yourself writing a lot of code where you assign a single scalar to an array and want to test that assignment in a boolean context? I don't, and I think there are good reasons why I don't.

      Do you find yourself constructing lists from several scalar expressions where the size of the resulting list should not change? I do. Quite a bit, actually. It is a natural thing to do in Perl. So things that return a scalar should return a scalar.

      Doing the "right thing" in a case that matters and is natural is much more important to me than doing the "right thing" in a case that I find doesn't matter (because it is unnatural).

      - tye        

        I'm assuming that you are defining "the right thing" as "being false".

        Yes, I am--for those functions where their return value should be unambiguously false when it's false.

        I should have been much more specific about that earlier.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-08-01 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (51 votes), past polls