Tuesday, July 17, 2007

statics are EVIL!!!

I made this statement a year or so ago while on a Microsoft lab engagement trip and I got some strange looks from some of the Microsoft folks over lunch. So here are my thoughts on why I believe use of statics is a bad idea.
  1. when you use a static you couple to an implementation and not an interface. You can not change the implementation without changing all dependencies.

  2. your statics are essentially global. Use of globals should be discouraged for the reason of intellectual manageability of your code. Strive to minimize the scope.

  3. using statics do not follow tenets of Object Orientation. Fine for your functional programming style but not OO.

  4. statics leads to all or nothing testing. Testing a single unit is much harder if not impossible.
For me it all comes down to testability. Some folks say that testing should not drive design but as I have said before, designing your code for more than one client leads to a much better and flexable design.

Of course this crazy talk will eventually lead you to Ioc. See you when you get there.

No comments: