Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: a sub within a sub -- revisiting

by punkish (Priest)
on Apr 10, 2010 at 06:13 UTC ( #833955=note: print w/replies, xml ) Need Help??


in reply to Re: a sub within a sub -- revisiting
in thread a sub within a sub -- revisiting

Actually, I disagree. The provided code is actually visually very helpful, as it leads (mind you, leads, not misleads) the reader to think that bar() makes sense in the context of foo().

From OOP we know that Perl doesn't protect methods and variables. Perl would much rather that you didn't come into its home uninvited than put locks on its doors. The reader of the code should simply not call bar() from outside foo().

That said, the suggestion to convert bar() into an anonymous sub is a good one. That makes things even clearer.

--

when small people start casting long shadows, it is time to go to bed

Replies are listed 'Best First'.
Re^3: a sub within a sub -- revisiting
by chromatic (Archbishop) on Apr 10, 2010 at 06:46 UTC
    The provided code is actually visually very helpful, as it leads (mind you, leads, not misleads) the reader to think that bar() makes sense in the context of foo().

    Maybe that code documents that its author intended such a thing, but to an experienced Perl programmer, I suspect that the code instead reads as if the author doesn't know how lexicals and sub declarations work in Perl.

Re^3: a sub within a sub -- revisiting
by AnomalousMonk (Canon) on Apr 10, 2010 at 07:16 UTC
    The ... code [of the OP] ... leads ... the reader to think that bar() makes sense in the context of foo().

    But does the code lead the reader to think that foo() does not make sense in the context of bar()? (See ikegami's Re: a sub within a sub -- revisiting.) If the code does not alert the reader to the subtle (side?) effect pointed out in that reply, it is not helpful and should either be heavily commented or another, more straightforward approach should be chosen to achieve the same effect. (Of course, this assumes the effect is intended in the first place!)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://833955]
help
Chatterbox?
[Lotus1]: perldigious I found out recently that opossums are very good at killing ticks.
Your Mother is lucky to only have to carry a kayak 15 feet to put in.
[perldigious]: If I was given the option to remove either mosquitos or ticks from the world... I think I'd pick ticks, even though I'd guess most would go the other way.
[Lotus1]: when they grooms themselves they eat any ticks they find. and apparently lots of ticks latch onto opossums.
[Your Mother]: There is a nice looking—don’t know first hand—new tool being market for removing ticks.
[Your Mother]: (marketed)
[Lotus1]: at least ticks don't fly
[1nickt]: We have a new tick in cenral New Jersey this year. The Lone Star tick -- no Lyme, but will give you an allergy to red meat!
[Your Mother]: "Tick Twister."
[1nickt]: My sister lives in the Sydney suburbs (carved out of the bush) and they have the Paralysis tick -- leavs you quadriplegic!

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2017-05-24 13:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?