Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: style guidance

by YuckFoo (Abbot)
on Nov 08, 2009 at 01:12 UTC ( #805706=note: print w/replies, xml ) Need Help??

in reply to style guidance

Not a huge fan of $_ here, I like named things. While it's neither difficult nor tricky to remember to use 'local $_ = shift;', it feels like a contrived and hoop-jumpish thing to do to avoid using a variable later. Just call it something. When there are multiple arguments, I like how the multiple shift style scales, easy to change the order, insert, delete and comment:
sub do_stuff { my $foo = shift; my $bar = shift; ... }
See What's so bad about &function(...)? for the style discussion about do_stuff(1, 2, 3) vs. &do_stuff(1, 2, 3).


Replies are listed 'Best First'.
Re^2: style guidance
by dsheroh (Monsignor) on Nov 08, 2009 at 12:55 UTC

    This question brings to mind chromatic's recent blog post on The Act of Naming. Granted, his post is about subroutine names and why you might want to create technically-superfluous subs purely for the sake of being able to name sections of your code, but the reasoning seems applicable to variables as well: Creating a new (lexical) variable with a good name is cheap, safe, and easy - cheaper and easier than the contortions demonstrated by some of the other responses' attempts to keep assigning to $_ safe - and it also helps to convey what your code is actually intended to accomplish. So JFDI.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-12-09 03:22 GMT
Find Nodes?
    Voting Booth?

    No recent polls found