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

Re^4: why avoid & on function call

by stevieb (Canon)
on Dec 28, 2020 at 17:28 UTC ( [id://11125881]=note: print w/replies, xml ) Need Help??


in reply to Re^3: why avoid & on function call
in thread why avoid & on function call

"Usually I add an explicit exit statement to the end of the 'main' part of the code before the subroutines so it is obvious where the 'main' block ends."

Meh, use an editor that folds sub code, and it's impossible not to easily see where main ends and subs begin.

I'm with talexb on the exit... to me, exit indicates an early emergency-type return. Although I don't put my main code within a block, I don't use exit either. I do though always put my main code before all of the sub definitions, unless there's a very good reason not to.

An exception to the main section blocks is in my test files. Each of my test files typically tests a single subroutine, and I like a pristine environment for every set of tests (eg. bad parameters, first parameter valid/invalid, second parameter valid/invalid etc), again with folding ability. eg:

# bad params {code-block} # validate date param format {code-block} # validate date param range {code-block} ...

I thought I wrote up an article once here on Perlmonks regarding folding Perl code, and turns out I was right. I also have a screenshot.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-23 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found