in reply to Re3: : Accessing Other Globals?
in thread Accessing Other Globals?

Please note that using global arrays is a sign that you have no idea how to correctly program your design (if you even have one)

Thank you for your help and the answer but to make this sort of a blanket statement is really nasty. You have no idea what I am doing with this. Perhaps I just want to learn something. Not only that but there are times when a global variable makes perfect sense. Do you respond the same way when someone brings up the goto statement? Get off your horse buddy.

Replies are listed 'Best First'.
Re5: Accessing Other Globals?
by dragonchild (Archbishop) on Dec 15, 2001 at 03:16 UTC
    *laughs* I am for intelligently-designed limited use of goto statements in non-production code. Just so you know.

    As for global variables making sense ... Yes, it is theoretically possible that a global variable is the "best" way to design a solution to a given problem. However, it has been my experience (and the experience of every skilled programmer I have ever talked to about this issue) that there has always been a better design solution.

    Now, if you're talking about hacking something together really quickly ... sure. Use all the globals you want! But, if you're working on designing something intended for longterm use, especially in OO, you'd have to talk really fast to convince me that globals are the best design solution.

    Just so you know, the solution I gave you involved what are called "symbolic references". They are, like globals and goto statements, considered to be almost universally bad. In fact, one monk has (had?) a sig that said you should never use symrefs unless you know why you shouldn't use symrefs. I've used symrefs in production code exactly once. In 6 years of programming Perl. Take that for what it's worth. (I've never needed to use goto in production code, and I've spent weeks encapsulating global variables into Exporter-driven modules.)

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

      It occurs to me, dragonchild, that the application in question might be reasonably sane ... if the global array in question is @ISA.

          -- Chip Salzenberg, Free-Floating Agent of Chaos

      Universal pronouncements are generally more effective when you suggest possible solutions. In this case if the object wants the data publically available, then it should define accessor methods for it. (And, of course, functions outside of its class should not assume that they know how said accessor methods work...)
Re (tilly) 5: : Accessing Other Globals?
by tilly (Archbishop) on Dec 15, 2001 at 20:54 UTC
    While dragonchild's form of never may have struck you as over the top, it is usually right. Though I generally say such things using phrases such as, Is generally a very bad idea.

    As for goto, my position on that is similar to my position on symbolic refs. If I see someone using it, I am likely to offer the advice that they shouldn't. Certainly someone who tries to tell me that unrestrained gotos are a good thing has just earned a bad opinion from me.

    Of course neither the statement that globals are bad or goto is evil are absolute. You can find better descriptions of my opinions at nodes like Pass by reference vs globals and Re (tilly) 4: Paradigm Shift - when to use goto. But they are true often enough that the absolute statement is a decent first approximation...