[Web4lib] global variables versus local variables
Erik Adams
EAdams at sheppardmullin.com
Mon May 23 14:18:56 EDT 2005
> Why is it more efficient to define a variable within a
> sub-routine?
It isn't more efficient at execute time; it's more efficient at coding,
debugging, and maintenance time. If simple variables (like loop
counters) are locally scoped, you don't have to worry about one function
modifying another's variables, potentially breaking an important test.
And, with modern computers, the performance loss is miniscule.
However, if your variable is expensive to create (time and memory
intensive), then the performance issues will overtake the coding
concerns. For example, if you're coding for IE and creating a lot of
ActiveX objects in Javascript, you might be better off creating a global
instance and just being careful to reset it locally.
Erik Y. Adams
Electronic Resources Librarian
Sheppard, Mullin, Richter & Hampton
eadams at sheppardmullin.com
(213)617-5429 / Fax: (213)620-1398
This message is sent by a law firm and may contain information that is privileged or confidential. If you received this transmission in error, please notify the sender by reply e-mail and delete the message and any attachments.
Sheppard, Mullin, Richter & Hampton LLP
Please visit our website at www.sheppardmullin.com
More information about the Web4lib
mailing list