in reply to Re^5: Module Announcement: Perl-Critic-1.01 (just a scalar)
in thread Module Announcement: Perl-Critic-1.01
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Module Announcement: Perl-Critic-1.01 ("right")
by chromatic (Archbishop) on Jan 27, 2007 at 03:10 UTC |