Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl-Sensitive Sunglasses
 
PerlMonks  

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).

YuckStyle


Comment on Re: style guidance
Download Code
Re^2: style guidance
by dsheroh (Parson) 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
Node Status?
node history
Node Type: note [id://805706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls