1. Very good points!

    I am not 100% opposed to the use of statics in all contexts — their use can be defensible in certain low-level technical situations, such as when a class wants to maintain a cache of data across its object instances, for performance reasons, but that caching is an implementation detail which should be transparent to the calling code.

    Mind you, I’m not saying that statics are *necessary*, even for that. And I agree that they get abused a lot more often than they get used legitimately, and that their very existence can encourage bad habits. Any code which uses statics tends to make unittesting a lot more painful, too. So I wouldn’t mind too much living in your world where modern programming languages simply did not have this feature.

    Agree on the static main, too. Although I don’t really like the alternative of kicking off the whole program from the constructor of the startup class. A constructor should do the minimum amount of work necessary to get the object into a well-defined state, and nothing more. Teaching novice OO programmers to run their entire program from within an object’s constructor, might give them an entire *other* set of bad habits. So I would perhaps use an overloaded operator() in C++, or make the startup class implement the Runnable interface in Java and then have the VM call its run() method.

    By the way, you may find this interesting also:
    I guess it’s fitting that the most obvious legitimate (even if not absolutely required) use for the ‘static’ keyword, is a design pattern which is already somewhat dubious in itself..

    Martin Wolf

  2. Hi Martin! Good to ‘see’ you again.

    Yes, I know the debate on singletons quite well. that is why I made a concealed reference to it. I dislike singletons perhaps even more than I do statics. I wanted to keep the discussion on topic and perhaps write another post about singletons but don’t hold your breath for that; there a lot on the web about them already.

    Erno de Weerd

  3. But…
    where do I leave my constants then? Or my globals? 🙂


  4. Static is not the solution for creating a constant. It’s like insisting that you need a nuclear bomb to scare the enemy and although a nuke can do that for you, it might not be the best or appropriate way to do that.

    As for globals: how global is global? Most globals are scoped to the running process. What if the user starts multiple instances of the same program? What if multiple users start the same program? Have you ever noticed that when the day comes that they find out (as they inevitably will) that Pi equals 4 we have a serious problem updating all software that defines Pi? How global is that definition? (and how constant is Pi any way?)


    Erno de Weerd

Comments are closed.