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

My reaction to what you describe is that both of you need to improve on design so that you don't think that you really need 30 variables all of the time. I wish I had a simple way to tell you how to do that, but without understanding why you are getting into that bind, I cannot really tell you how to avoid needing that many variables. (I suspect that understanding that phrase, Think loose coupling that you see from time to time on pages here might help.)

But after that, both solutions have problems. Globals raise the possibility of promiscuous interaction between code, which causes all of the usual debugging issues. Passing variables protects you from that, and documents what you are using, but raises issues with how your argument lists are structured. If you are positionally placing 30 arguments, then you are using copy and paste. What happens if you want to add an argument? Hopefully you are using hashes to allow you to work by name.

Likewise the answers that people are offering have issues. If you start using hashes, how do you do typo checks? I have offered solutions to that in the past. But most of those solutions (rightly IMO) require you to wind up carefully thinking through which variables are needed in which functions. Passing references to hashes you directly access is likewise problematical for the reasons that I stated at Pass by reference vs globals.

No. The real problem is that you are trying to manage a large amount of common data. That is a task which raises inherent issues. And solving that is probably a design issue.

  • Comment on Re (tilly) 1: Use globals or pass around everything under the sun?