[AccessD] Using Global Connctions

John W. Colby jcolby at colbyconsulting.com
Thu Mar 13 16:31:01 CST 2003


Marcus,

>It's built around them being sloppy coding practice in any programming
language.

Precisely.  Sloppy programming habits.  Globals serve a purpose, but they
should be few and far between.

The biggest problem is that anyone can SET them.  And that always leads to
problems.  By having "Read only" globals, i.e. globals that are set by (for
example) a class opening and having no way to otherwise set the global, or
having functions that check the write to the global to ensure that they are
not being trashed accidentally goes along way towards ameliorating the
problem.

BTW, global really is a misnomer.  You have scope.  Global can be global to
a class (for instance), where any function in the class can read / write the
variable.  Global can be global to a module, where any object in the module
can read / write the variable, but nothing outside the module can see the
variable.  Or it can be truly global where anything in the entire
application can read / write the variable.  Much of the problem with globals
is that they have to be understood by everyone that can see them (has them
in their scope).

Class global variables are actually quite useful.  Since a class typically
has a single author, that author understands the purpose, and therefore can
use the global appropriately.  I routinely dim my class variables private in
the header, set them, then access them directly in the functions inside the
class.  Why pass things around unnecessarily?

OTOH, a truly global variable can be set (and cleared) by anyone who has
access to the code.  Again, that is not necessarily bad, there is a time and
a place, but to do that with every variable you create leads to chaos.

John W. Colby
Colby Consulting
www.ColbyConsulting.com

-----Original Message-----
From: accessd-admin at databaseadvisors.com
[mailto:accessd-admin at databaseadvisors.com]On Behalf Of Marcus, Scott
(GEAE, RHI Consulting)
Sent: Thursday, March 13, 2003 7:18 AM
To: 'accessd at databaseadvisors.com'
Subject: RE: [AccessD] Using Global Connctions


Drew,

Calling it a lame debate because they are considered unstable shows your
lack of
understanding the debate. The Global debate is not centered around myth. It
isn't even centered around them being unstable (they are no less stable than
any
other variable). The debate isn't even centered around using global
variables in
Access. It's built around them being sloppy coding practice in any
programming
language. Global variables have their use but, they lead to spaghetti code
(I
didn't say they are spaghetti code they LEAD TO). Do you agree that when a
function that sets a global variable or uses a global variable in some
calculation, where in the heck is that variable set and under what
conditions is
it set or not set? Sure, in a small application that is easy enough to track
down. How many times have your Access applications grown into something much
larger than planned for? It is a fact that globals make the code harder to
read
and understand. As a programmer, it is much more important that I easily
understand how the code works so that I can modify it with minimal risk to
error. Globals increase that risk significantly in large applications. I
can't
even count the number of times that I've gotten lost in the code of a large
application (written by someone else) by tracking down multiple global
variables
used in a function.

Calling it a lame debate is an excuse to ignore bad coding habits. I'm not
saying that you have bad coding habits. I'm saying that they can become a
bad
habit. I don't personally know if you are at that level or not.

I have never thought globals to be 'flaky', just a bad habit. Less than a
few in
an application doesn't constitute a bad habit. But having them plastered
everywhere (instead of passing data as parameters in functions or subs) is a
bad
habit.

BTW A global connection could be a good use of a global variable.

Scott


-----Original Message-----
From: Drew Wutka [mailto:DWUTKA at marlow.com]
Sent: Wednesday, March 12, 2003 5:07 PM
To: 'accessd at databaseadvisors.com'
Subject: RE: [AccessD] Using Global Connctions


Actually, of all the 'big' debates I have seen on the list, the Global one
is pretty lame.  Most of the debates get into heated discussions over the
fine tunings of an application, or the database engine, or even picky
details of theory.  The Global issue is really centered around a myth.  The
myth is that they are unstable.  This is entirely untrue.  A global variable
holds a value for the life of your session.  Now, in VB, when you have an
.exe, or you run a project in debug mode, when you hit 'end', or stop your
code, your entire project stops, so you expect your globals to disappear.
However, in Access, stopping your code doesn't close forms, or shut anything
down, it just stops the running code.  The Globals are 'lost', but that is
because your code has stopped running.  Since the database still looks
intact, Globals have gotten the impression that they are 'flaky'.  

Do you see what I am saying?

Drew

-----Original Message-----
From: Marcus, Scott (GEAE, RHI Consulting)
[mailto:scott.marcus at ae.ge.com]
Sent: Wednesday, March 12, 2003 12:46 PM
To: 'accessd at databaseadvisors.com'
Subject: RE: [AccessD] Using Global Connctions


Drew,

I miss the debate we had last time on globals. Fortunately I'm not Borg so
resistance is not futile. I wonder if JC is paying attention.

Scott

-----Original Message-----
From: Drew Wutka [mailto:DWUTKA at marlow.com]
Sent: Wednesday, March 12, 2003 1:31 PM
To: 'accessd at databaseadvisors.com'
Subject: RE: [AccessD] Using Global Connctions


Love Globals.
They are just as reliable as any other code.
If someone did, it would be me! <VBG>
Sometimes.
Yes, all the time.  I 'hit and release' my ADO Connections all the time,
especially when on a LAN.  In fact, the first vergence from that practice
just happened last night.  I am working on a web interface to a Contact
Request database.  The database is on our Internet Web Server, and the Web
interface is on our Intranet Web Server.  Creating the connection through
the network (from server to server) takes about half a second to a second
(didn't really time it...).  I have multiple classes working on each page,
each of which require db interaction.  Opening and killing the connection
creates unacceptable delays (3 to 4 seconds per page load...I know that's
not too bad, but in comparison to almost instantaneous pulls with the method
I am using now, there is a big difference).  So what I did, was take a major
'class', which represents information about the person logged in (it's used
in every page), and I load an instance of that class, if it hasn't been
loaded.  If it has been loaded, I pull the class from a Session variable,
which has already been loaded.  That class keeps the connection open while
the class is live, so I can then pass the connection object to other
classes, keeping it open the entire time.

With that method, the first page on the site (whatever page is hit) takes a
few moments to load, but from that point on, the site runs as fast as the
user can click.  I left the default timeout of 10 minutes on the session
object, so as long as the user doesn't wait more then 10 minutes before
doing something on the site, they won't experience the temporarily delay in
the  main class loading.

Drew

-----Original Message-----
From: Mark L. Breen [mailto:subs at solution-providers.ie]
Sent: Wednesday, March 12, 2003 3:35 AM
To: accessd at databaseadvisors.com
Subject: [AccessD] Using Global Connctions


Hello All,

As a follow up to Susan Harkins discussion on the command object,

How do you guys use a global connection in your apps

What I have been doing is initialising gccnn when I load the app.  It is G
lobal C onstant cnn.

I then use this Global variable for every ADO section of code.

Do you hate global variables?
do you think that they are unreliable?
do you think that someone is going to come in the middle of the night and
wipe it out?
Do you use a class or property pass it around instead?
In a fat client, LAN, does anyone initialise it and close it each time? (I
presume not)

Just intested in your feedback

Thanks



_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



----------------------------------------------------
Is email taking over your day?  Manage your time with eMailBoss.  
Try it free!  http://www.eMailBoss.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 5944 bytes
Desc: not available
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030313/e8acb4ef/attachment-0001.bin>


More information about the AccessD mailing list