|
-
Nov 9th, 2006, 11:13 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Global variables: when to use, if ever?
The app I'm writing has just had its global variables ripped out...by me. I used them on the recommendation of our team leader but I've gone behind his back and changed them from global variables to local only to the module they're in.
I'm wondering if I've gone too far, and also if there's ever a reason to use a global variable in VB, specifically VB6.
Thanks.
-
Nov 9th, 2006, 11:58 AM
#2
Re: Global variables: when to use, if ever?
Public (global) variables are necessary part of any program that requires some values to be available across multiple modules/objects/forms/etc...
So if you changed them all to local then how are you going to access any of it?
-
Nov 9th, 2006, 12:01 PM
#3
Re: Global variables: when to use, if ever?
 Originally Posted by disruptivehair
...but I've gone behind his back and changed ...
BTW, that was not a good idea - you are not working for yourself so you may get fired.
-
Nov 9th, 2006, 02:18 PM
#4
Thread Starter
Hyperactive Member
Re: Global variables: when to use, if ever?
 Originally Posted by RhinoBull
BTW, that was not a good idea - you are not working for yourself so you may get fired. 
He won't care; he said global variables were a good idea but in all honesty they leave me to do 100% of the work. As long as the program continues to work I don't think they'll care; there are no standards.
-
Nov 9th, 2006, 02:18 PM
#5
Thread Starter
Hyperactive Member
Re: Global variables: when to use, if ever?
 Originally Posted by RhinoBull
Public (global) variables are necessary part of any program that requires some values to be available across multiple modules/objects/forms/etc...
So if you changed them all to local then how are you going to access any of it?
Public functions that grab the value of the variable.
-
Nov 9th, 2006, 04:17 PM
#6
Re: Global variables: when to use, if ever?
 Originally Posted by disruptivehair
... As long as the program continues to work I don't think they'll care; there are no standards.
That's a true way to create a chaos - each business must have some kind of rules that works for them best.
Programmers come and go but business stays so if everyone is to write something on their own it may (and it will) create a disaster situation when things are unmanageable.
But good luck to you and your team lead.
-
Nov 10th, 2006, 04:02 AM
#7
Thread Starter
Hyperactive Member
Re: Global variables: when to use, if ever?
 Originally Posted by RhinoBull
That's a true way to create a chaos - each business must have some kind of rules that works for them best.
Programmers come and go but business stays so if everyone is to write something on their own it may (and it will) create a disaster situation when things are unmanageable.
But good luck to you and your team lead.
That's pretty much how things operate here; they've blended a bunch of teams and they all have their own way of doing things.
I should add that I changed the global variables because everything I've read so far indicates that you should keep the scope of your variables as narrow as possible. I'm the only one developing this application; the others don't have a hand in it and don't look at the code so I don't think the impact of changing them will be that great. Obviously I never would do this if I thought it would screw up other peoples' work. We're moving back to the USA in a few months at which point the project will simply be handed off to another person.
It's interesting how much people have different opinions about this. My husband, who primarily does grid computing and whose main languages are Java and C++, said what I did was the correct thing. So I dunno.
In any case, the app works and I think the changes I made make it easier to understand...but you know what they say about opinions.
-
Nov 10th, 2006, 09:29 AM
#8
Re: Global variables: when to use, if ever?
You did the "right thing" only if you don't need to keep data globally or you will be forced to run some sub/function otherwise.
Wich way works better for you - you are the one to determine.
There isn't right or wrong - it's what's necessary that matters. And what language someone is using is quite irreelvant in this case - concept is the same.
Best regards.
-
Nov 10th, 2006, 09:34 AM
#9
Thread Starter
Hyperactive Member
Re: Global variables: when to use, if ever?
 Originally Posted by RhinoBull
You did the "right thing" only if you don't need to keep data globally or you will be forced to run some sub/function otherwise.
Wich way works better for you - you are the one to determine.
There isn't right or wrong - it's what's necessary that matters. And what language someone is using is quite irreelvant in this case - concept is the same.
Best regards.
I do need to pass the data between modules. At this point I don't know what to do, I won't change the code back unless I'm ordered to but I doubt anyone will even notice anyway. The impression that I got were that global variables were bad and I should avoid using them at all costs.
It's hard to know who to listen to sometimes when you hear wildly varying opinions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|