|
|
Warp wrote:
> You are on the right track, though: Global variables should and can
> be avoided
While generally true, I find that if the *meaning* of a variable is
truly global, it can be made a global harmlessly.
FILE * resourcefule;
// The handle to the resource file if it's open, or NULL if not.
Stuff like that. If there's ever an instant where the definition of the
variable doesn't match its content, then it isn't global, it's just a
backdoor to pass parameters between functions.
Of course, with OO more than procedural code, you're more likely to pull
a class into some other framework where it wasn't expected to be, so
there's less good use for globally-visible variables. (Unless, of
course, your language treats classes as globals, rather than as second
class objects.)
But I've never regretted making a global that was truly global in that
sense, so anyone could reference it. "Bad" globals are ones that don't
have a meaningful value for the entire duration of the program, from the
first line to the last, methinks.
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
|