in reply to Use globals or pass around everything under the sun?

Use hashes or, even better, hashes-that-can-have-methods-called-through-them (aka, objects). This will allow you to bundle stuff.

(You will be using references to hashes, not the hashes themselves, right?)

You are correct in that passing in tons of variables will make the code cleaner. You have an interface between the main program and the modules.

As for the other programmer's thoughts, he's probably right. But, he also suffers from premature optimization. Is passing the variables around causing a noticeable slowdown? If it isn't, then there's nothing to optimize!

My suggestion would be to try them both.

What's that you say? Too much work? Your implementation is too tightly tied to your interface? Sounds like you've got work ahead of you. :-)

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

  • Comment on Re: Use globals or pass around everything under the sun?

Replies are listed 'Best First'.
Re: Re: Use globals or pass around everything under the sun?
by demerphq (Chancellor) on Dec 05, 2001 at 16:54 UTC
    Im so glad you posted this. Its basically what I was going to say too.

    Whenever I find I am dealing with large numbers of parameters getting passed around I create an object to hold them all, and then either pass it around or subclass it.

    One advantage to having an object to pass around is that it provides an single point that the programmer can go to see what possible variables exist. This is in some respects better than subclassing as you dont have zillions of layers of additional stuff.

    My only criticism of you post is that IMO there should not be more than a few parameters to a suboutine. The more parameters a subroutine takes the more difficult it is to understand what it does, and to make mistakes with regard to their position (addmittadly this can be dealt with via named parameters) or omission. Usually this isnt that big a deal, except that it can have a dramatic slowdown on development time and frustration levels.

    Yves / DeMerphq
    --
    Have you registered your Name Space?

      Heh. I wasn't going to get into refactoring, though that sounds like what's needed here...

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