Tech Off Post

Single Post Permalink

View Thread: Gilad on cutting out static
  • User profile image

    Only a couple of thoughts (it has been a long day).

    Whilst it is true that the use of statics is both imperative (as in the style of) and involves taking a lot more care of how it is used, there are benefits which are not necessarily outweighed by the disadvantages.  

    Implement a local cache without statics, now do it without passing references back up the call stack from the owner of the non-static cache all the way to the place where it is actually needed. 

    I can see Gilad's point about distributed systems, and the difficulty in maintaining the 'one true static' but that isn't such an issue if you aren't building a distributed system.

    His points about re-entrancy, whilst true, depend totally on your usage. Personally a lot of my use of statics tend to be read-only after an initial locked update, so I'm not so worried after any threading issues. 

    Yeah, he has lots of great points, but how would I build my Factories and Caches and Blackboards without statics?

    I think we'd all agree that he could write the same document about pointers and that'd be true as well, but I don't think pointers being evil (or not) warrants eliminating them from C (or C++) or is likely to ever be considered.  Same goes for statics, and as with pointers, use it carefully and it won't bite you.