Vladimir Prus


vladimirprus.com

Friday, January 14, 2005

Change to a better design: not necessary change for a better

Say you have a better design for something. Is changing to that better design a good thing? Not necessary.

For example, let's look at the sad story of C runtime library in C++. When namespaces were invented, it was decided that in C++, contents of the C runtime library will be in the std namespace. Seems like a better design, but change to that better design creates a lot of problems.

  1. Compilers did not switch in an instant. Some have the C runtime in the std namespace now, and some don't. As the result, you need macro logic in every module which uses the C library. Or you need your own header file for each C library header, and must make sure that you always include only your replacement headers, not the standard ones.
  2. It is convenient to add
    using namespace std;
    
    to the top of a source file (not header!) and then use unqualified names everywhere. Unfortunately, you can get an error about an ambiguity between global name and the std:: name. This happens, for example, with msvc/stlport combination and is a compiler bug.
  3. You won't expect that error from better compilers, but standard library which ships with one of them declares global functions with extern "C" and std:: without. Again, the compiler reports ambiguity. This time the compiler is correct, and the problem is with the library.

Today, I certainly know more about those quirks that I would like. Was moving the C library to std:: a good idea? Decide for yourself.

No comments: