Re: static props and methods = global variables??

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Stu Smith (stuarts_at_nospam-digita.com)
Date: 07/19/04


Date: Mon, 19 Jul 2004 16:03:53 +0100


"Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@comcast.netNoSpamM> wrote
in message news:%23Z428X0aEHA.3352@TK2MSFTNGP12.phx.gbl...
> The only question to ask is how often the items are going to be used. If

I think it's also worth considering lifetime as well. A global variable can
have an unclear or badly defined lifetime, and that can cause you problems.

> regularly, then keeping variables in memory is not a bad thing. I
routinely
> use a singleton for application settings. The singleton stores all sorts
of

As an example, do these app settings ever get written as well as read? If
not then fine, but if so you have a lifetime issue -- when do they get
written? As another example, what if the application settings need to change
midway through execution?

Many types of static/global data could really be considered a cache of some
sort (as in the app config example), and the golden rule there is "caching
implies policy" -- if you can't tell me the policy, you're likely to have
problems.

(And to anticipate Mr. Beamer's reply, the policy there is probably
'read-only; lifetime must extend at least until last access; small data vs.
relatively slow access to original data makes it worth it').

> vars, which makes a convenient object that can be used again and again. As
a
> singleton, it gets created the first time it is requested, so I do not
have
> an app ramp up time, per se.
>
> Static variables/properties are a good means of holding config type
> information, if that is what you are asking. Static methods are great for
> helper methods that do not require individual state.
>
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>
> ************************************************
> Think Outside the Box!
> ************************************************
> "Daniel Billingsley" <dbillingsley@NO_durcon_SPAAMM.com> wrote in message
> news:OCkv3U0aEHA.3988@tk2msftngp13.phx.gbl...
> > I'd like to set (on launch) and then keep some AppDomain-wide variables.
> >
> > Is there anything "bad" with doing something like this (dumb example),
or
> is
> > there another more "standard" way of accomplishing it?
> >
> > public class SomeInfo
> > {
> > private static _someText;
> >
> > public static string Text
> > {
> > get { return _someText; }
> > }
> >
> > public static void SelectText(int option)
> > {
> > if (int==1)
> > _someText = "one";
> > else
> > _someText = "something else";
> > }
> >
> > }
> >
> >
>
>



Relevant Pages

  • Re: Tim, help me unmask a murderer
    ... > Is worth a lifetime ... didn't know you're JRD fan :-) ... Prev by Date: ...
    (comp.sys.ibm.ps2.hardware)
  • Re: Stamp collection appraisal
    ... but the dealer is buying material with no known immediate buyer, ... your lifetime, though, you may be in for a surprise at how little it ... all is worth. ...
    (rec.collecting.stamps.discuss)
  • Re: Less than 12 hours
    ... Pretty much half my lifetime ago. ... That's worth a *sigh* if anything is.) ... Merry Christmas and a happy New Year! ...
    (comp.sys.sinclair)
  • Re: Tim, help me unmask a murderer
    ... Is worth a lifetime ... Floppy in hand, I ascend the Silver Mountains. ...
    (comp.sys.ibm.ps2.hardware)
  • Re: Multithreading
    ... large app to .NET. ... I might as well go with Delphi at that point, ... "needs .NET framework", and as soon as I read this, my interest in the ... As for *developing* in and for .NET, not in my lifetime! ...
    (microsoft.public.vb.general.discussion)