POV-Ray : Newsgroups : povray.off-topic : C++ structuring help.... : Re: C++ structuring help.... Server Time
10 Oct 2024 17:17:59 EDT (-0400)
  Re: C++ structuring help....  
From: Darren New
Date: 21 Mar 2008 12:43:11
Message: <47e3f3af$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.