Board index » Visual Studio » Global Variables - A problem?

Global Variables - A problem?

Visual Studio118
Some time ago a poster "ranted" about not using public/global variables.



Ocassionaly I use them - but it's clear they are global (like

blnPublicStatusFlag)



What are the pros and cons?



(If pro is the opposite of con, is progress the opposit of congress? :-)



Thanks

Mark


-
 

Re:Global Variables - A problem?

In article <#BMY6hSAEHA.2448@TK2MSFTNGP12.phx.gbl>, Mark Durrenberger

<durrenm@yahoo.com>writes

Quote
Some time ago a poster "ranted" about not using public/global variables.



Ocassionaly I use them - but it's clear they are global (like

blnPublicStatusFlag)



What are the pros and cons?



I always use them for 'global' type information such as Company Name

etc. As far as I'm concerned, the overhead of continually passing such

basic, static type information as parameters doesn't make sense. Read

the stuff from the database once and store in well commented global

variables in the 'initialise' routine.



In 'worker' functions/routines, I always pass the 'input' in as

parameters and use local variables for stuff that will not be 'used'

outside of the routine.



Even the all singing all dancing OO technology that rants against global

variables has them . . . if class variables and instance variables are

not a 'global', then pigs can fly.

--

Jane Ransom in Lancaster.

If you need to email me for any other reason, put ransoms

at jandg dot demon dot co dot uk where you see ransom@deadspam.com





-

Re:Global Variables - A problem?

"Mark Durrenberger" <durrenm@yahoo.com>'s wild thoughts were

released on Wed, 3 Mar 2004 09:04:00 -0500 bearing the

following fruit:



Quote
Some time ago a poster "ranted" about not using public/global variables.



Ocassionaly I use them - but it's clear they are global (like

blnPublicStatusFlag)



What are the pros and cons?



(If pro is the opposite of con, is progress the opposit of congress? :-)





Sooner or later apps get too large, and you may make the

decision to split it up. This is *far* more difficult if

your app contains a lot of public variables.



Your code is not sharable, often you find you could use a

routine, form, module etc in another project. If everything

is written like a black box (everything gets passed in) then

you can share a component with any other project slashing

development time. If you rely on global variables you would

then not only have to add all these into the new project,

but set them too.



When you write a routing where everything it needs is passed

in it's far easier to debug. If it relies on globals it can

be very hard to find out where that global ended up with a

suprising value.



Read up on object orientated programming (OOP) for more

information.







--

Jan Hyde (MVP - Visual Basic)



A chorus girl gets her education by stages, a college girl by degrees.

(The International Save the Pun Foundation)



[Abolish the TV Licence - www.tvlicensing.biz/]">www.tvlicensing.biz/]



-

Re:Global Variables - A problem?

I don't see how anyone can rant about them or advise against

them. After all, App is a global variable and there are many other

global types. All the type declarations, Long, Integer, Double,

Single, are all global definitions.



I tend to mark my own global variables with a g- prefix. Form wide

variables are marked with an m- prefix. And all localized variables

are marked with str-, lng-, i-, etc Hungarian prefixes (almost all).



This tends to make the code very easy to read at any date in the

future and helps when diagnosing problems. Now I've run into a few

problems with one thing in particular, and I think alot of folks run

into this same problem.



Anywhere that an error can be trapped, I tend to use:

Private Sub subDoTheStuff()

On Error Goto LocalErr

'...code here to do what's needed.

'...code

'...code

Exit Sub 'or Exit Function

LocalErr:

gStrErr = ERRMSG & CStr(Err.Number) & vbCrLf & Err.Description

gSubError gStrErr, "modName/subDoTheStuff"

End Sub



The problems I've run into with the LocalErr thing above, include

the possibility that an error can occur in a routine that has no

trapping set up. It's rare, but it can happen and it might make

diagnosing and troubleshooting things a little tricky.



So my thoughts on this subject are to always set up an error trap

if there's any possibility at all of some error that might occur.



Hope that helps.

--

Jim Carlock

www.microcosmotalk.com/">www.microcosmotalk.com/

Post replies to the newsgroup.





"Mark Durrenberger" <durrenm@yahoo.com>wrote in message

Some time ago a poster "ranted" about not using public/global variables.



Ocassionaly I use them - but it's clear they are global (like

blnPublicStatusFlag)



What are the pros and cons?



(If pro is the opposite of con, is progress the opposit of congress? :-)



Thanks

Mark







-

Re:Global Variables - A problem?

Or add a database to the project.



E.g. Microsoft Registry.



Almost everything in the registry is a global variable. <g>



--

Jim Carlock

www.microcosmotalk.com/">www.microcosmotalk.com/

Post replies to the newsgroup.





"Jan Hyde" <StellaDrinker@REMOVE.ME.uboot.com>wrote in message

"Mark Durrenberger" <durrenm@yahoo.com>'s wild thoughts were

released on Wed, 3 Mar 2004 09:04:00 -0500 bearing the

following fruit:



Quote
Some time ago a poster "ranted" about not using public/global variables.



Ocassionaly I use them - but it's clear they are global (like

blnPublicStatusFlag)



What are the pros and cons?



(If pro is the opposite of con, is progress the opposit of congress? :-)





Sooner or later apps get too large, and you may make the

decision to split it up. This is *far* more difficult if

your app contains a lot of public variables.



Your code is not sharable, often you find you could use a

routine, form, module etc in another project. If everything

is written like a black box (everything gets passed in) then

you can share a component with any other project slashing

development time. If you rely on global variables you would

then not only have to add all these into the new project,

but set them too.



When you write a routing where everything it needs is passed

in it's far easier to debug. If it relies on globals it can

be very hard to find out where that global ended up with a

suprising value.



Read up on object orientated programming (OOP) for more

information.







--

Jan Hyde (MVP - Visual Basic)



A chorus girl gets her education by stages, a college girl by degrees.

(The International Save the Pun Foundation)



[Abolish the TV Licence - www.tvlicensing.biz/]">www.tvlicensing.biz/]





-

Re:Global Variables - A problem?

"Jane Ransom" <ransoms@deadspam.com>wrote in message

<cut>

Quote
Even the all singing all dancing OO technology that rants against

global variables has them . . . if class variables and instance

variables are not a 'global', then pigs can fly.



How are they global? a class instance variable can be defined local to a

particular procedure and there will be nothing 'global' about it.



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

"Jim Carlock" <anonymous@127.0.0.1>wrote in message

Quote
I don't see how anyone can rant about them or advise against

them. After all, App is a global variable



There are some global objects provided by VB and it can make sense to define

something in your own app as global but I've learned the hard way that while

it can seem like an easier approach in the initial coding it can make

maintenance more difficult if global variables are overused. They prevent

effective encapsulation of functionality making it harder to create reusable

objects and code. Like most things they are not inherently 'evil' (only END

is evil) and there are cases where they may be appropriate but any time you

are making something global you should probably consider other approaches

that don't tie your components to external data.



Quote
and there are many other

global types. All the type declarations, Long, Integer, Double,

Single, are all global definitions.



data type definitions aren't in the same category as global variables; when

you create a class or a form or a public procedure in a BAS module you are

creating something that is available globally just like the data types you

mention are available globally.



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

I like flying pigs... ;)

How ever, I never use Global Varibles...

I only use Public ones.... <BeG>



I'm not an advocate of using many many Public varibles even though I do use them

a lot. It was how I learned to program (non-winders os) and it has just migrated

along with me.

There are a few reasons, valid ones, not to use them if you can do it else wise

using good programming techniques and I'm sure others will mention most of them

so I'll not venture into them here...



On Wed, 3 Mar 2004 15:18:54 +0000, Jane Ransom <ransoms@deadspam.com>wrote:



Quote
In article <#BMY6hSAEHA.2448@TK2MSFTNGP12.phx.gbl>, Mark Durrenberger

<durrenm@yahoo.com>writes

>Some time ago a poster "ranted" about not using public/global variables.

>

>Ocassionaly I use them - but it's clear they are global (like

>blnPublicStatusFlag)

>

>What are the pros and cons?

>

I always use them for 'global' type information such as Company Name

etc. As far as I'm concerned, the overhead of continually passing such

basic, static type information as parameters doesn't make sense. Read

the stuff from the database once and store in well commented global

variables in the 'initialise' routine.



In 'worker' functions/routines, I always pass the 'input' in as

parameters and use local variables for stuff that will not be 'used'

outside of the routine.



Even the all singing all dancing OO technology that rants against global

variables has them . . . if class variables and instance variables are

not a 'global', then pigs can fly.



Have a good day...



Don

-

Re:Global Variables - A problem?



"Mark Durrenberger" <durrenm@yahoo.com>wrote in message

Quote
Some time ago a poster "ranted" about not using public/global variables.



Ocassionaly I use them - but it's clear they are global (like

blnPublicStatusFlag)



What are the pros and cons?



(If pro is the opposite of con, is progress the opposit of congress? :-)



Thanks

Mark





Mark,



Jane pointed out the major problem with globals, when she noted that when

used for 'universal' reads (eg, the App object) globals are generally

benign. However, they become problematic when 'reads' and 'writes' are

involved, for then you enter into the realm of concurrency and validity.



It is not wise to have far-flung routines chewing on the same animal. Even

when you feel you have good control over who or what is writing and who or

what is reading - even simple changes to your code can result in an

application-wide hunt and repair.



Also 'globals' by their very nature imply external data and routines to

manage them, leading one to procedural or data-centric solutions. Again

benign when used for 'reads', a misery waiting-to-happen if used for

volatile storage. An object that is dependent on external data - is a poor

object indeed.



HTH

-ralph







-

Re:Global Variables - A problem?

Quote
Like most things they are not inherently 'evil' (only END is evil)



What's wrong with END? I use it **all** the time... End Function, End Sub,

End If, End While, End Select, End Type <g>.



Rick





-

Re:Global Variables - A problem?

"Rick Rothstein" wrote:

Quote
>Like most things they are not inherently 'evil' (only END is evil)

What's wrong with END? I use it **all** the time... End Function,

End Sub, End If, End While, End Select, End Type <g>.



Rick



End Enum too!



--

Jim Carlock

www.microcosmotalk.com/">www.microcosmotalk.com/

Post replies to the newsgroup.







-

Re:Global Variables - A problem?

Quote
>>Like most things they are not inherently 'evil' (only END is evil)

>What's wrong with END? I use it **all** the time... End Function,

>End Sub, End If, End While, End Select, End Type <g>.



Rick



End Enum too!



Yeah, End Property too. There are probably others we've forgotten in there

also.



Rick





-

Re:Global Variables - A problem?

"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in message

Quote
>Like most things they are not inherently 'evil' (only END is evil)



What's wrong with END? I use it **all** the time... End Function, End

Sub, End If, End While, End Select, End Type <g>.



End While ? Have you defected?



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

"Bob Butler" <tiredofit@nospam.com>wrote

Quote
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net>wrote



>What's wrong with END? I use it **all** the time... End Function, End

>Sub, End If, End While, End Select, End Type <g>.



End While ? Have you defected?





Touché



<g>

LFS





-

Re:Global Variables - A problem?

In article <exAsIlTAEHA.712@tk2msftngp13.phx.gbl>, Bob Butler

<tiredofit@nospam.com>writes

Quote
"Jane Ransom" <ransoms@deadspam.com>wrote in message

news:aHIMebAedfRAFwhJ@jandg.demon.co.uk

<cut>

>Even the all singing all dancing OO technology that rants against

>global variables has them . . . if class variables and instance

>variables are not a 'global', then pigs can fly.



How are they global? a class instance variable can be defined local to a

particular procedure and there will be nothing 'global' about it.



An instance variable is available to all methods in an instance of a

class. A class variable is available to all instances of a class.

I call that pretty global in nature!!!!

--

Jane Ransom in Lancaster.

If you need to email me for any other reason, put ransoms

at jandg dot demon dot co dot uk where you see ransom@deadspam.com





-

Re:Global Variables - A problem?

In article <nf0c409nvu70pd1q1ubneoen8rdvtcctq3@4ax.com>, Don@home.com

writes

Quote
I like flying pigs... ;)

How ever, I never use Global Varibles...

I only use Public ones.... <BeG>



Duuuuuuuuuh :))))

--

Jane Ransom in Lancaster.

If you need to email me for any other reason, put ransoms

at jandg dot demon dot co dot uk where you see ransom@deadspam.com





-

Re:Global Variables - A problem?

Wow go away from your desk for a few hours and look what happens...



Great thread thanks for all the comments

Quote


It is not wise to have far-flung routines chewing on the same animal. Even

when you feel you have good control over who or what is writing and who or

what is reading - even simple changes to your code can result in an

application-wide hunt and repair.



This, to me, is perhaps the most compelling point for not using globals

though I'd have not mixed my metaphors to say it.



Can someone tell me how to write a routine that 'chews' ? ;-)



Thanks,

Mark







-

Re:Global Variables - A problem?

"Jane Ransom" <ransoms@deadspam.com>wrote in message

<cut>

Quote
An instance variable is available to all methods in an instance of a

class.



You mean something defined at the module-level inside a class? That is

available to anything in the class but not outside the class unless it is

public. The class itself still encapsulates that data and there should only

be module-level variables for items that are needed in multiple procedures

inside the class. It's a big step down from application global.



Quote
A class variable is available to all instances of a class.

I call that pretty global in nature!!!!



Show me the code that defines that.



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

Public variables are like public restrooms.



Wipe the seat before you sit on them!



--

Jim Carlock

www.microcosmotalk.com/">www.microcosmotalk.com/

Post replies to the newsgroup.





"Bob Butler" <tiredofit@nospam.com>wrote in message

"Jane Ransom" <ransoms@deadspam.com>wrote in message

<cut>

Quote
An instance variable is available to all methods in an instance of a

class.



You mean something defined at the module-level inside a class? That is

available to anything in the class but not outside the class unless it is

public. The class itself still encapsulates that data and there should only

be module-level variables for items that are needed in multiple procedures

inside the class. It's a big step down from application global.



Quote
A class variable is available to all instances of a class.

I call that pretty global in nature!!!!



Show me the code that defines that.



--

Reply to the group so all can participate

VB.Net... just say "No"





-

Re:Global Variables - A problem?

"Jane Ransom" <ransoms@deadspam.com>wrote



Quote
>How are they global? a class instance variable can be defined local to a

>particular procedure and there will be nothing 'global' about it.

>

An instance variable is available to all methods in an instance of a

class. A class variable is available to all instances of a class.

I call that pretty global in nature!!!!





I think you are are confused, either of what to call the different variables,

or of their actual operation.



Taken one at a time:

Quote
An instance variable is available to all methods in an instance of a

class.



Dim cla As Class1

Set cla = New Class1



'cla' is the instance variable, and it will not be visible to the methods

in that class.



Quote
A class variable is available to all instances of a class.



I am not sure what you are calling a class variable. Classes have

Properties, and Methods (Subs and Functions) What is a class

variable?



LFS





-

Re:Global Variables - A problem?



"Mark Durrenberger" <durrenm@yahoo.com>wrote

Quote
Great thread thanks for all the comments



Can someone tell me how to write a routine that 'chews' ? ;-)





Take a routine that massages data, and add a little bite to it!



<g>

LFS





-

Re:Global Variables - A problem?

Bob Butler wrote:

Quote
Like most things they are not inherently 'evil' (only END

is evil)



Nope, sorry; I do wish that was all.



Type Coercion is evil.

Option Base is evil; unspecified lower array bounds are at least naughty.

String concatenation using the addition operator is evil.

Flag-bit gathering using the addition operator is evil.



(and the list goes on...)





Bob

--

looking for work again <obob.com/bob/resume/>">obob.com/bob/resume/>

-

Re:Global Variables - A problem?



Quote


Take a routine that massages data, and add a little bite to it!



<g>

LFS



So if Garrison Keillor wrote code that massaged data would that be swedish

massage code?



<grin>





-

Re:Global Variables - A problem?

In article <e45wAbVAEHA.3004@TK2MSFTNGP10.phx.gbl>, Bob Butler

<tiredofit@nospam.com>writes

Quote
"Jane Ransom" <ransoms@deadspam.com>wrote in message

news:UJjvtdAxShRAFwh+@jandg.demon.co.uk

<cut>

>An instance variable is available to all methods in an instance of a

>class.



You mean something defined at the module-level inside a class? That is

available to anything in the class but not outside the class unless it is

public. The class itself still encapsulates that data and there should only

be module-level variables for items that are needed in multiple procedures

inside the class. It's a big step down from application global.



>A class variable is available to all instances of a class.

>I call that pretty global in nature!!!!



Show me the code that defines that.



I think we have our knickers in a bit of a twist here :)



If you look back at my original post, I am talking pure OO as in

Smalltalk and Java.

Are we allowed to post Java code in this group?

--

Jane Ransom in Lancaster.

If you need to email me for any other reason, put ransoms

at jandg dot demon dot co dot uk where you see ransom@deadspam.com





-

Re:Global Variables - A problem?

In article <eFplXkVAEHA.3308@TK2MSFTNGP10.phx.gbl>, Larry Serflaten

<serflaten@usinternet.com>writes

Quote


I think you are are confused, either of what to call the different variables,

or of their actual operation.



Nope - as I said, I am talking pure OO not VB's version of it.

I know, I know, it's not on topic for this group and I apologise :)

I'm sorry . . . I'll go back in to my shell and belt up !!!

--

Jane Ransom in Lancaster.

If you need to email me for any other reason, put ransoms

at jandg dot demon dot co dot uk where you see ransom@deadspam.com





-

Re:Global Variables - A problem?

"Bob O`Bob" <filterbob@yahoogroups.com>wrote in message

Quote
Bob Butler wrote:

>Like most things they are not inherently 'evil' (only END

>is evil)



Nope, sorry; I do wish that was all.



Type Coercion is evil.

Option Base is evil; unspecified lower array bounds are at least

naughty. String concatenation using the addition operator is evil.

Flag-bit gathering using the addition operator is evil.



Those aren't "evil" in my book, just nasty... a matter of degree I suppose

<g>



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

"Mark Durrenberger" <durrenm@yahoo.com>wrote in message

Quote
>Take a routine that massages data, and add a little bite to it!

>

><g>

>LFS



So if Garrison Keillor wrote code that massaged data would that be

swedish massage code?



No, just the most *incredibly*, mind-numbingly boring code you ever saw.



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

"Jane Ransom" <ransoms@deadspam.com>wrote in message

Quote
In article <e45wAbVAEHA.3004@TK2MSFTNGP10.phx.gbl>, Bob Butler

<tiredofit@nospam.com>writes

>"Jane Ransom" <ransoms@deadspam.com>wrote in message

>news:UJjvtdAxShRAFwh+@jandg.demon.co.uk

><cut>

>>An instance variable is available to all methods in an instance of a

>>class.

>

>You mean something defined at the module-level inside a class? That

>is available to anything in the class but not outside the class

>unless it is public. The class itself still encapsulates that data

>and there should only be module-level variables for items that are

>needed in multiple procedures inside the class. It's a big step

>down from application global.

>

>>A class variable is available to all instances of a class.

>>I call that pretty global in nature!!!!

>

>Show me the code that defines that.

>I think we have our knickers in a bit of a twist here :)



If you look back at my original post, I am talking pure OO as in

Smalltalk and Java.

Are we allowed to post Java code in this group?



Ahh... I was assuming you were talking in relation to VB. Comparing to pure

OO is fine by me but if you mentioned that I missed it.



As for having knickers in a twist I'm afraid that's not very likely as I

don't even own any knickers! <g>



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

Careful, I'm a big fan...



Quote
No, just the most *incredibly*, mind-numbingly boring code you ever saw.



--

Reply to the group so all can participate

VB.Net... just say "No"







-

Re:Global Variables - A problem?

Bob Butler wrote:



Quote
>Type Coercion is evil.

>Option Base is evil; unspecified lower array bounds are at least

>naughty. String concatenation using the addition operator is evil.

>Flag-bit gathering using the addition operator is evil.



Those aren't "evil" in my book, just nasty... a matter of degree I suppose

<g>





It certainly is evil when _Microsoft_ actively promotes code samples

which do those nasty things, causing many neophytes to accept

and learn those "worst practices" as if they were best.







Bob

--

looking for work again <obob.com/bob/resume/>">obob.com/bob/resume/>

-

Re:Global Variables - A problem?

"Bob O`Bob" <filterbob@yahoogroups.com>wrote in message

Quote
Bob Butler wrote:



>>Type Coercion is evil.

>>Option Base is evil; unspecified lower array bounds are at least

>>naughty. String concatenation using the addition operator is evil.

>>Flag-bit gathering using the addition operator is evil.

>

>Those aren't "evil" in my book, just nasty... a matter of degree I

>suppose <g>



It certainly is evil when _Microsoft_ actively promotes code samples

which do those nasty things, causing many neophytes to accept

and learn those "worst practices" as if they were best.



Yes, that I agree with. I can't believe how bad most of the sample VB code

was (past tense since it's getting harder and harder to find now and even

bad examples were better than none!)



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

Bob Butler <tiredofit@nospam.com>wrote:

Quote
"Bob O`Bob" <filterbob@yahoogroups.com>wrote in message

>It certainly is evil when _Microsoft_ actively promotes code samples

>which do those nasty things, causing many neophytes to accept

>and learn those "worst practices" as if they were best.



Yes, that I agree with. I can't believe how bad most of the sample VB code

was (past tense since it's getting harder and harder to find now and even

bad examples were better than none!)



Here ya go... msdn.microsoft.com/code/">msdn.microsoft.com/code/ ;-)

--

[Microsoft Basic: 1976-2001, RIP]





-

Re:Global Variables - A problem?

"Karl E. Peterson" <karl@mvps.org>wrote in message

Quote
Bob Butler <tiredofit@nospam.com>wrote:

>"Bob O`Bob" <filterbob@yahoogroups.com>wrote in message

>>It certainly is evil when _Microsoft_ actively promotes code samples

>>which do those nasty things, causing many neophytes to accept

>>and learn those "worst practices" as if they were best.

>

>Yes, that I agree with. I can't believe how bad most of the sample

>VB code was (past tense since it's getting harder and harder to find

>now and even bad examples were better than none!)



Here ya go... msdn.microsoft.com/code/">msdn.microsoft.com/code/ ;-)



I'm surprised; I thought most of the VB6 stuff had been archived and/or

hidden better than that.



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

"Bob Butler" <tiredofit@nospam.com>wrote in message <news:#gBzKIZAEHA.4080@TK2MSFTNGP09.phx.gbl>...



Quote
"Karl E. Peterson" <karl@mvps.org>wrote in message

news:eSnYMLYAEHA.2348@TK2MSFTNGP09.phx.gbl

>Bob Butler <tiredofit@nospam.com>wrote:

>>"Bob O`Bob" <filterbob@yahoogroups.com>wrote in message

>>>It certainly is evil when _Microsoft_ actively promotes code samples

>>>which do those nasty things, causing many neophytes to accept

>>>and learn those "worst practices" as if they were best.

>>

>>Yes, that I agree with. I can't believe how bad most of the sample

>>VB code was (past tense since it's getting harder and harder to find

>>now and even bad examples were better than none!)

>

>Here ya go... msdn.microsoft.com/code/">msdn.microsoft.com/code/ ;-)



I'm surprised; I thought most of the VB6 stuff had been archived and/or

hidden better than that.



The support articles having to do with VB5/6 are probably toast,

but the bad coding practices rampant in their code samples still

have tactical value in leading VB Classic programmers astray and

encouraging the notion that good code can be written only in B#.



--

Joe Foster <mailto:jlfoster%40znet.com>Sign the Check! <www.xenu.net/>">www.xenu.net/>

WARNING: I cannot be held responsible for the above They're coming to

because my cats have apparently learned to type. take me away, ha ha!





-

Re:Global Variables - A problem?



"Mark Durrenberger" <durrenm@yahoo.com>wrote in message

Quote
Wow go away from your desk for a few hours and look what happens...



Great thread thanks for all the comments

>

>It is not wise to have far-flung routines chewing on the same animal.

Even

>when you feel you have good control over who or what is writing and who

or

>what is reading - even simple changes to your code can result in an

>application-wide hunt and repair.



This, to me, is perhaps the most compelling point for not using globals

though I'd have not mixed my metaphors to say it.



Can someone tell me how to write a routine that 'chews' ? ;-)



Thanks,

Mark





LOL



My hoosier (the land of mixed-metaphors) roots are often exposed. I like the

words massage and mangle as well.



Too many years teaching OO to newbies I guess. I mean how many times can you

say 'mutable' before people's eyes start to glaze?



-ralph





-

Re:Global Variables - A problem?



"Jane Ransom" <ransoms@deadspam.com>wrote in message

Quote
In article <exAsIlTAEHA.712@tk2msftngp13.phx.gbl>, Bob Butler

<tiredofit@nospam.com>writes

>"Jane Ransom" <ransoms@deadspam.com>wrote in message

>news:aHIMebAedfRAFwhJ@jandg.demon.co.uk

><cut>

>>Even the all singing all dancing OO technology that rants against

>>global variables has them . . . if class variables and instance

>>variables are not a 'global', then pigs can fly.

>

>How are they global? a class instance variable can be defined local to a

>particular procedure and there will be nothing 'global' about it.

>

An instance variable is available to all methods in an instance of a

class. A class variable is available to all instances of a class.

I call that pretty global in nature!!!!

--

Jane Ransom in Lancaster.

If you need to email me for any other reason, put ransoms

at jandg dot demon dot co dot uk where you see ransom@deadspam.com





I suppose if one wants to define something as 'global' to a smaller space,

then I guess you could call them global. Just as you can say an automatic

variable is 'global' to the procedure in which it is defined. However, I

don't believe that is what the original inquirer had in mind.



The implementation of a instance varible mimics in many ways the definition

of a static variable within a procedure (in fact, in some languages they are

defined as "static") only with wider scope.



However they may be implemented - references and access to them is very

clearly defined and limited, thus managed as a collaboration between objects

and ownership. More importantly - the same warning is in effect for their

use - Instances variables are relatively benign when used for 'reads' but

carry subtle opportunities for disaster when used for reads and writes.



-ralph





-

Re:Global Variables - A problem?

"Ralph" <nt_consulting32@hotmail.com>wrote in message

<cut>

Quote
Too many years teaching OO to newbies I guess. I mean how many times

can you say 'mutable' before people's eyes start to glaze?



1



--

Reply to the group so all can participate

VB.Net... just say "No"



-

Re:Global Variables - A problem?

On Wed, 3 Mar 2004 16:28:27 -0800, "Bob Butler"

<tiredofit@nospam.com>wrote:

in <Oa4Fg#XAEHA.712@tk2msftngp13.phx.gbl>



Quote
"Bob O`Bob" <filterbob@yahoogroups.com>wrote in message

news:40464E2F.337E@yahoogroups.com

>Bob Butler wrote:

>

>>>Type Coercion is evil.

>>>Option Base is evil; unspecified lower array bounds are at least

>>>naughty. String concatenation using the addition operator is evil.

>>>Flag-bit gathering using the addition operator is evil.

>>

>>Those aren't "evil" in my book, just nasty... a matter of degree I

>>suppose <g>

>

>It certainly is evil when _Microsoft_ actively promotes code samples

>which do those nasty things, causing many neophytes to accept

>and learn those "worst practices" as if they were best.



Yes, that I agree with. I can't believe how bad most of the sample VB code

was (past tense since it's getting harder and harder to find now and even

bad examples were better than none!)



It's a little easier to believe when you factor in the $245 fee

for a call to PSS...

-