On 04/17/2012 07:03 AM, 'lesleyb' wrote:
On Mon, Apr 16, 2012 at 04:20:35PM +0200, Paul Johnson wrote:
On Mon, Apr 16, 2012 at 06:53:53AM -0700, Paul.G wrote:
Hi All
Have a question, is it good coding practice to use a& when calling a
subroutine, or it is not required, or it doesn't matter?
It's good practice not to use it unless you understand exactly why you
would need to use it.
I'm tempted to say +1 for a really uninformative answer :)
well, it is actually a useful answer. i say things like you shouldn't
use a certain feature (e.g. symrefs, string eval, etc.) until you know
when to not use them. they are dangerous or obscure things which newbies
may not get easily or quickly. explaining why can be difficult and not
worth the immediate effort. it can be best to say don't and explain
later on when they have more experience.
perldoc perlsub (http://perldoc.perl.org/perlsub.html) explains the '&' is
entirely optional - except where it isn't - e.g. where you might need to check
if the subroutine exists, use a reference to a subroutine rather than a direct
call etc.
There are provisos to the use of the '&' prefix and the documentation explains
those.
you see, that was not helpful. there are negatives (not just provisos)
to using & for sub calls. you didn't state them but only paraphrased the
docs. if you think the previous comment was not good, yours is worse as
it makes it seem like using & is up to the coder ("entirely optional").
it isn't. it is bad coding in several ways. it isn't needed, it marks
the code as perl4ish or newbie, and it has those downsides that i won't
mention but which are documented. the rule is simple and doesn't need
need deep explanation. you don't use & for plain sub calls. period.
thanx,
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/