in reply to Re: subroutines and namespace
in thread subroutines and namespace

Yes, that'd do it. Very neat - possibly nicer than the solution I went with, of using fully specified package variables from my module. Only disadvantage is a few more characters of code... which are marginal even if I'm intent on Higher Laziness.

My main point was a general one, however, that sometimes one wants to have subroutines with the same scope as the point from which they're called. Just as often one does *not* want this. I wondered whether I was alone in thinking this might be a useful thing to be able to do - in a lot of different situations.

§ George Sherston

Replies are listed 'Best First'.
Re3: subroutines and namespace
by dragonchild (Archbishop) on Nov 02, 2001 at 19:20 UTC
    Actually, you would never want to care where the subroutine's scope is. And, the reason why is that it would violate encapsulation.

    The way to think about a subroutine is that it's a self-contained unit of activity. It receives inputs, does stuff, and gives outputs. It should NEVER depend on the caller's scope. It should NEVER depend on anything but that which is within its own personal scope (which should be inviolate and untouchable by caller).

    Every single legitimate reason you would want to do what you suggest is negated by a language feature or design change that will make your code more maintainable and easier to work with.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.