Monday, June 27, 2011

The "C/C++" myth

Seeing C and C++ referred to as "C/C++" perplexes me to no end. Writing "C/C++" makes no sense at all. You almost always want either C or C++, as the two have widely disparate areas of suitability.

The two languages seem to be shrouded in a good number of myths, that I would like to debunk


Myth: There is a language "C/C++"

There is no language "C/C++". C and C++ have very little in common. Yes, I know C++ evolved from C, but that fact aside, the two languages are very different. C++ has a lot more in common with basically any given object oriented language than it does with C.


Myth: C++ is the next version of C

C++ is C with an object system grafted onto to it (object orientation is not a more evolved form of imperative programming, even though it's more suitable for some tasks).

The next version of C is C1x.


Myth: C++ is backwards compatible with C

At some point, it was. But today, C++ is not backwards compatible with C, with void pointers and whatnot.


Myth: If you know C++, you know C

This is a superficial truth. You may know the syntax of the language, but this does not make you a good C programmer. The C language has a large number of limitations, and to overcome these requires a lot of experience in C.

C++ has other ways of overcoming these limitations, and there generally is no way to directly translate these to C. Finally, imperative C++ code is bad C++ code, not C code.

As a side note, this is why speed comparisons between C and C++ are typically pathological. If you compile a piece of C code in C++, it will run at the same speed as it would in C. But code in the wild is not going to be side-stepping the object system like that.

No comments:

Post a Comment