Are Global Variables Really that bad ? (1 Viewer)

Thales750

Formerly Jsanders
Local time
Today, 07:13
Joined
Dec 20, 2007
Messages
2,081
A poor design well implemented does not make it a good design. I doubt any database developer is going to agree that a database application with hundreds of public variables is a good design. Maybe someone will. I would be very interested if you find someone on this forum that agrees this is a good approach. I have no doubt that you can make this work, but most people will agree that there are better smarter ways. Encapsulation, data integrity, debugging, fault tracing, etc, etc. Back in the old days before Object Oriented programming and event driven programming there was no other way than maintaining lots of globals, I think those days are gone.

I can take the worst non-normalized database and slap on some slick forms and enough vba and people will think it is great. It will work great. But that does not make it good and would not recommend it.

There may be times to use a public variable, but most of the time there is a better way.

Not saying this is your case, because I am sure you are very knowledgeable. But in general when I see applications with lots of public/global variables the developer does not know (some or all):
1. How to pass arguments to procedures
2. How to return values from functions
3. How to build a parameterized query definition
4. How to pass and return values from forms
5. How to build custom classes
6. How to build user types
7. How to do enumerations

When a developer only has a hammer everything looks like a nail.

In Access if you absolutely need to use a global variable then use a TEMPVAR. I do not use TEMPVARS much, but if there was a pressing need to use a global variable then there is no reason not to use a TEMPVAR instead. (unless for some reason you need to have a global variable that is an object). A TEMPVAR was specifically made so that you can use it in a query without an additional function. TEMPVAR functions like a global variable but has advantages.
When I look at your file, I would assume all those values are coming from a table/s and could be easily accessed. So why you would need most of those variables?
A lot of people, many of them on this forum are stuck in boxes. As it turns out I apparently don't know the difference between Public Variables and Global Variables. Be it as it may my database are driven by queries. Public Variables as Public Functions are a great way to write SQL code, It's clean, concise, and runs fast. I'm not trying to convert anyone, don't care to save the world, but experts make the worst example of closed mindedness.

Edison and Westinghouse are excellent examples of that, just ask Tesla.
 

isladogs

MVP / VIP
Local time
Today, 12:13
Joined
Jan 14, 2017
Messages
18,209
A lot of people, many of them on this forum are stuck in boxes. As it turns out I apparently don't know the difference between Public Variables and Global Variables. Be it as it may my database are driven by queries. Public Variables as Public Functions are a great way to write SQL code, It's clean, concise, and runs fast. I'm not trying to convert anyone, don't care to save the world, but experts make the worst example of closed mindedness.

Edison and Westinghouse are excellent examples of that, just ask Tesla.
Of course, many developers will stick to the same approaches which they have used for years.
I'm sure that I'm guilty of that to some extent and it sounds like you are as well
Sometimes, its hard for all of us to accept that there may be better methods available to us.

I'm not going to get involved in whether I think what you are doing is / isn't good practice.
However, if you re-read my comments at the beginning of this lengthy thread, you may get some idea of my viewpoint back in 2017

Whatever the merits (or otherwise) of your approach, you seem to be demonstrating exactly what you are referring to here
i.e. being 'stuck in boxes' and 'closed mindedness'
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:13
Joined
Sep 12, 2006
Messages
15,634
^^^^
I thought he seemed to have been surrounded by villains.
 

Users who are viewing this thread

Top Bottom