DWUTKA at marlow.com
DWUTKA at marlow.com
Tue May 17 10:22:37 CDT 2005
Well, I will meet you on the 'when there is a valid reason for doing so' part. As for the used sparingly, well, I think that is not quite right. You should dimension variables based on their scope. Global variables are one of three scopes. If you need a Global variable, then dimension it. If your app is overloaded with Global variables, if that is what you need, it is what you need. If you are not saying that they 'go away' as an argument, why do you consider them 'bad practice' still? Drew -----Original Message----- From: John W. Colby [mailto:jwcolby at colbyconsulting.com] Sent: Monday, May 16, 2005 5:33 PM To: 'Access Developers discussion and problem solving' Subject: RE: [AccessD] Global Variable Drew, I have a library (C2DbFW3G) that I use for all of my global code. There are thousands of lines of code, dozens of classes, hundreds of functions and NO global variables. They are completely unnecessary and no code outside of the framework itself has any business directly setting variables in the framework. I have plenty of private variables, initialized by the framework as it starts up, and I have a handful of functions that return the values in the private variables in the framework, but the variables themselves are not directly settable. Even from inside the framework, there are NO global variables. In my applications, I have a handful of global variables. I use them where they are absolutely needed, and there are a handful of places in my app where that is true. I do NOT use them as a convenience to avoid programming. I do not use them to make something faster without knowing that the speed increase is critical. Excuses like "they speed up the app" are just that, excuses. Speed is not the end all and be all of an application and speeding up something that is not a bottleneck at the expense of poor programming practices is not a good reason to use a global. The statement I made was "don't get carried away with them, they are considered bad practice in general". There is nothing about that statement that is wrong. They are considered bad practice "in general". They should be used sparingly. Every tool has a purpose, and global variables exist, therefore they must have a purpose. I did not make any statement that global variables should never be used, I simply said "don't get carried away with them". BTW I do NOT use "they go away" as a reason for not using them. In my estimation there should be no unhandled errors. The error handler insertion wizard that I co-wrote will assist the developer in getting an error handler in every single function in the project if that is necessary. There ARE valid reasons for using a global, but they are few and far between. There ARE valid reasons not to use global variables, many of them, all related to avoiding and finding bugs. If there were not valid reasons for not using them, then you would not have scope for variables. Your opening sentence seems to imply that there is no good reason not to use them and that simply is not true. Let's meet in the middle and agree that Globals should be used sparingly and only when there is a valid reason for doing so. John W. Colby www.ColbyConsulting.com Contribute your unused CPU cycles to a good cause: http://folding.stanford.edu/ -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of DWUTKA at marlow.com Sent: Monday, May 16, 2005 5:01 PM To: accessd at databaseadvisors.com Subject: RE: [AccessD] Global Variable First of all, if there WAS a valid argument for Global Variables, I wouldn't say a lick about a bad practice comment. But there is none, JC. I know I'm not the only self taught person on the list. As for books, and reading...honestly, I read fantasy adventure, science fiction, and the occasion 'odd' non-fiction book. (Reading the Lucifer Principle right now...it's an interesting take on human psychology). As far reading to learn....hmmmmm.....obviously I can't say that I never read anything on programming, databases, etc, that would be ludicrous. I obviously have. But, I do differentiate between fact and belief. 1/0 will generate and error. That's a fact. Global variables are bad practice...that's a belief. As for the rest....nice sarcasm...I've missed our discussions.....it warms my blood to have you responding like this! I'm getting all giddy! <grin> Your younger, and obviously less experienced and knowledgeable servant.... Drew -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com