Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Module Announcement: Perl-Critic-1.01

by Jenda (Abbot)
on Jan 27, 2007 at 00:52 UTC ( #596807=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Module Announcement: Perl-Critic-1.01
in thread Module Announcement: Perl-Critic-1.01

So I guess you'd rather do

my $pointless_reference = $obj->getPosition(); my ($x, $y) = @$pointless_reference[0,1];
or
my ($x, $y) = @{$obj->getPosition()};
instead of
my ($x, $y) = $obj->getPosition();
right? Restricting myself to returning just one value just because most languages do not allow anything more seems silly to me. Especially compared to such dirty tricks as updating the values of some variables passed by reference or something.

To me bending backwards to always return a single scalar is a code smell. A code smell sugesting that the author writes C or some other language, but definitely not Perl. Even though the code is full of sigils and there are regexps scattered around.


Comment on Re^4: Module Announcement: Perl-Critic-1.01
Select or Download Code
Re^5: Module Announcement: Perl-Critic-1.01
by Rhandom (Curate) on Jan 29, 2007 at 19:07 UTC
    Absolutely!

    I think that the following is perfectly fine.
    my ($x, $y) = @{ $obj->getPosition }
    Depending upon the interface I think that it may be better to return a point reference or object rather than the xy coordinates themselves.
    my $point = $obj->getPosition; do_something_with_point($point); printf "X is %.2f\n", $point->x; # or maybe $point->[0] - possibly bad # or maybe $point->{x} - probably bad # but really $point->x is the best

    It is funny that you should use a geometry example. Many of the C or C++ libraries that I have seen that deal with graphics primitives prefer to pass around a point struct rather than the individual x or y.

    Just because it is possible to make interchanged data as terse as possible doesn't mean it is the right thing to do.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];

      C or C++ cannot do anything better anyway. I think we can't convince each other so let's just hope we do not meet in one company and on the same project since this is one of the seemingly unimportant style issues that drive people crazy ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-11-28 03:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (192 votes), past polls