John W. Colby
jwcolby at colbyconsulting.com
Mon May 16 14:50:00 CDT 2005
Drew, You make it sound as if you are the only one "self taught". I am sure you will find many people on this list "self taught", many of them every bit as capable as yourself. On the other hand, what is "self taught"? Do you read books? There is no way to learn anything without reading something about it (or be taught by someone who read something about it). Did you load VB on your machine and start typing in random characters trying to get it to do something? Somehow I doubt it. I have no special love for the educational establishment, on the other hand millions of people have spent billions of hours studying things that you and I could never get around to thinking about. To refuse to consider the thoughts of others is ludicrous. Your programming style (or lack thereof) reflects your own biases, and may not necessarily be very useful to anyone but yourself. Or, you may be insanely brilliant and in 50 years programmers will be studying your works as physicists now study Einstein's. And then again there are the incumbent thought obstacles that you obviously already possess which cause you to deride accepted practices. Accepted practices exist to attempt to work around problems. If you don't have time to think of every scenario, but mankind by virtue of shear numbers runs into uncounted situations that you can't possible understand or know about, then how can you deride attempts to deal with these issues that you know nothing about? No one says you have to accept every "accepted practice" at face value, but without thorough understanding of the reasons behind them, to reject them out of hand is foolish and often dangerous. Since I know that you are not foolish (I will leave dangerous for another day) I assume therefore that you have spent many years understanding the finer points of all of these accepted practices and, having full knowledge of all the ins and outs, reject them. At your tender age to have come to such an understanding is indeed a massive accomplishment. My hat is off to you, and I hope some day to reach such a point myself. Sadly, given that I too am (almost ashamed to say now) self taught, and my life is much further along than yours, I am not sure I will ever find the time to catch up with your profound understanding. In awe and humble fawning, Your unworthy student, 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 2:50 PM To: accessd at databaseadvisors.com Subject: RE: [AccessD] Global Variable You know, I think this whole debate could be avoided, again, if it was just stated that using global variables when a 'lesser' scope should be used, is bad practice. I know I get into these discussions, because I am self taught, and it takes a LOT more energy to overcome incumbent thought obstacles then it does to learn new things. Drew -----Original Message----- From: John W. Colby [mailto:jwcolby at colbyconsulting.com] Sent: Monday, May 16, 2005 12:31 PM To: 'Access Developers discussion and problem solving' Subject: RE: [AccessD] Global Variable Gustav, There are many things generally considered poor programming practice in the programming industry. Excessive use of Gotos and Global variables are a couple of examples. In general they ARE CONSIDERED (by myself and many many many other people) to be bad programming practices. Globals, like Gotos are handed down from the days of old when there was no such thing as functions, data types declarations, scope and the many other tools that make modern programming worlds above the code written 40 years ago. All of these things exist for a reason. Globals are considered poor programming practice because they expose variables to update and even overwriting by code that has no business updating that variable. It is generally accepted practice that variables should have the minimum exposure absolutely necessary to perform their function. A variable used ONLY in a specific function should NOT EVER be declared as a global variable. A variable used ONLY in a module should NOT EVER be declared a global. Microsoft and other compiler writers provide tools like variable scope for a good reason, they help minimize, and track down bugs. If a variable is private to a module then if that variable is being updated incorrectly, you at least know it is because of some code in that module. If it can be updated anywhere in the entire program then you must search the entire program when something goes wrong. Function level variables (declared inside a function) are local to the function and cannot be declared otherwise. Thus the "excessive use" of globals would include making a variable, intended for use in a module, global "just in case". I personally make it a practice to always explicitly declare module level variables private Private MyVar as SomeVarType unless there is an over-riding reason to expose the variable on a global basis. Even then I make it a practice to build a function that reads a private variable in those cases where code in other modules must be able to read the variable. Only in cases where code in multiple modules must both read and write a global variable will I expose the variable itself as a global. And even in those cases it is sometime useful to cause the write to go through a function, particularly if the variable is a computed value. Global variables is one of those issues that strikes a sensitive note with many programmers, but it is indeed widely accepted to be poor programming practice to just use them willy-nilly and for no good reason. Every tool exists for a reason and variable scope is a very powerful tool to assist the programmer in writing better code. 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 Gustav Brock Sent: Monday, May 16, 2005 12:34 PM To: accessd at databaseadvisors.com Subject: RE: [AccessD] Global Variable Hi John You may like or prefer or need, or not, a global variable - that's up to everyone to decide for him/herself - but they are not "bad practice", not even in general. You may write clumsy code using globals, but not using them gives no guarantee for nice code. /gustav