Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: style guidance

by YuckFoo (Abbot)
on Nov 08, 2009 at 01:12 UTC ( [id://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).

YuckStyle

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

    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-04-16 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found