Sign in to follow this  
Dragon_Lance

pros and cons of Global Variables and Local Variables?

Recommended Posts

I typically stick all my variables inside a class and make them private so that only the class can change them. That way it is very easy to group and categorize the code in a logical manner.

If I create a global I'll usually make is constant so that no one can change it.

Share this post


Link to post
Share on other sites
Personally I prefer to never use global variables for the same reason that proper encapsulation of classes is so important.

Global variables make your code very hard to maintain and aren't necessary in even a mediocrely designed system.

Local variables on the other hand are used as required (within the scope of whatever function in which they are defined). Are you confusing them with member variables?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this