Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: How To Link Variables from different procedures Posted by PP2005 on 20 May 2008 at 11:19 PM
: The reason it's considered bad programming is because of linkage
: between modules (in this case a "module" means a procedure and
: function). It has nothing to do with memory.
:
: No module should have access to any variable that it does not need
: to have access to. That way if a programmer changes a variable in
: one module it has no effect on a similarly named variable in another
: module. A global variable can be changed by any procedure/function.
: It's not hidden.
:
: Read ELEMENTS OF PROGRAMMING STYLE and SOFTWARE TOOLS IN PASCAL,
: both by Brian Kernighan and P.J. Plauger.


Well, then just don't use names for local variables that match those of global variables. In my game code I couldn't imagine how I'd do it without global variables. I have hundreds of variables that are used by 75% of my procedures and functions (also in the hundreds). Passing them between these procedures and functions would be a nightmare. Having them as global variables removes this headache. When I have to access one, I just do it. I haven't had any problems with local and global variables sharing names. I just don't see how this is considered a problem, but maybe that's just me.
Thread Tree



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.