Thoughts from Greg Comeau on C++, OO, Programming, Learning

(c) © 1990-2013 Comeau Computing. All Rights Reserved.
I have a number of thoughts I will be providing here from time to time. The first set will be about books and learning C++. I hope to have this available by summer 2000. Check back soon for those details and other information.
-- Greg

Here's a first entry (July 23, 1999):
Why do some people say that C is still better than C++?
Can't they see that C++ is a superset of C, and that although C++ has additional features, it does not force you to use them?

Clearly languages can become "religious" for some folks, and so some people are just being biased. However, "pure" C definitely remains in play in areas such as:

  1. Legacy systems
    Some folks still need even K&R C.
  2. The cost of retraining (in C++) is not (yet) practical for some.
    This often ties in with (1), but doesn't have to.
  3. The platform you are on does not have a C++ available.
    This is clearly much less so than previously, but still valid in some cases (though we're always available to port Comeau C++).
  4. Culture/first language/etc.: Some people just love C and/or just don't like C++
IMO, (1) is the only real long term barrier for some projects, though (2) and (3) clearly have economic ties that would be clearly impractical/prohibitive for many companies.

On a strictly technical basis though, I agree with the initial questions. Taking a literal perspective, C++ is not a true super set of C, but from a practical perspective it is. Most ANSI C'd code is also easily C++'d code too. For instance, all the code in K&R's 2nd "ANSI C" edition of The C Programming Language can be (and in fact was) compiled with a C++ compiler.

This then begs these questions/issues which come up often:

  1. Is there any C style which cannot be used in C++?
    I don't know any. Therefore, it is immediately useful.
    And in most cases, w/o a penalty.
  2. Is there not one thing in C++ that looks attractive to the C++ nay sayers?
    I find it hard to believe that anybody would say no.
    Again, this makes it immediately useful.
  3. Don't I have to use the OO parts of C++?
    No, not at all.
  4. If I don't use C++ for OO, then what use is C++, why not just stick with C?
    Let me elaborate on the previous response then. No, you don't have to use the OO parts of C++ at all, though I wouldn't know why you wouldn't if it were appropriate. C++ is often termed an OOL, however, I very much prefer to say that's misguided and instead to say that C++ is a multi-paradigmed language. And oh, BTW, one of those paradigms is OO. This is significant because C++ also supports all the C styles, just data abstraction, plus generic programming, etc. Who are you to say what's best for something without knowing about it?

    Consider a recent discussion I observed. In the discussion, one person said something along the lines of that somebody wouldn't be much of a C++ programmer if they couldn't write straight C code too. This met a response that if somebody used C++ just to write plain old C, then they still were not much of a good C++ programmer! The latter person correctly pointed out that a good C++ programmer wouldn't necessarily program like a good C programmer would.

    Then again, neither person brought forth the issue that we all have different needs to address in our work e