Henrik Nordstrom wrote:
> Tor 2008-04-17 klockan 21:19 +0530 skrev Paras Fadte:
>
>> With respect to C++ , is a static member of a class like a global
>> variable?
>
> Yes, a class scoped (not object) global variable.
>
>> Does OOP in particular consider use of a static/global
>> variable as a bad programming practice?
>
> Most do..
>
> But it do make life a lot easier..
Which for leads to a few well-known problems, and the reasons why its
often considered bad. I'm not hypocritical to outlaw it, but advise
Programming carefully if you think you need any.
I judge it based on the objects design.
- 'manager' type class with only one instance static/global can be
useful, simpler, and faster. Especially to guarantee the rule that there
is only one. Go ahead consider it.
- minor object likely to have several usages or re-usage, static
becomes a major headache.
- static variable in functions called recursively, MAJOR headache.
globals, I don't think are as evil as made out to be. Often a little
thought can lead you to conclude a direct need for being global. Or to a
way of cleanly scoping them somewhere so it does not matter.
My cleanup side-project is going through the main squid headers testing
all the usages these days.
Amos
-- Please use Squid 2.6.STABLE19 or 3.0.STABLE4Received on Tue Apr 22 2008 - 14:41:53 MDT
This archive was generated by hypermail 2.2.0 : Wed Apr 30 2008 - 12:00:07 MDT