Having used both extensively, I can tell you that it is much more difficult to write slow, bloated, overly complex code in C than in C++. It keeps you honest in that way. Also, most of the good things of C++ such as object-oriented programming and templating can be done at a basic level in C. For example, in C++, a class function is just an ordinary function with a hidden pointer to a (class) structure. Why not just pass in a pointer to a class structure in C? And class member privacy can easily be a matter of naming convention rather than something the compiler enforces.
C++ has its value, and may be better suited for building large, complex, systems such as GUI frameworks, but C is a great choice for cases where speed and minimal size are paramount, such as most embedded code as well as the Linux kernel. In principle, it's possible to write fast, small code in C++ by using its features selectively. However, if you do that, you're left with mostly just the features you could have emulated in C anyway.
Oh, and did I mention that in its current form C is the "perfect" programming language? Other languages have their own goals, but judged in terms of its own goals, C does what it's trying to do better than just about any other language - far better than C++ meets its goals. There's a reason that changes to C over its many years have been very minimal, and virtually always for the better.
>For example, in C++, a class function is just an ordinary function with a hidden pointer to a (class) structure. Why not just pass in a pointer to a class structure in C?
GNOME does this. It's great for everything except writing concise, readable C code. They have a language on top of this called Vala, which uses GNOME's type system (and in fact compiles to C) but without having to write complex object and type initialization code. But AFAIK not a lot of people use it.
It's been ages since I read Stroustrup or Kernighan & Ritchie, as I have largely moved on from embedded/Unix programming into Web based systems but I seem to recall one of the arguments for using C++ was that it could always do things as efficiently as C and possibly more so.
Likely true, but the benefit of C that I'm highlighting is that it gives you very little rope to hang yourself with in terms of creating a system composed of layer-upon-layer of classes. In contrast, I once worked with someone who loved to create class-upon-inherited-class for the simplest things in C++. Everyone who looked at his code wondered "where's the beef?", that is, the part that did something useful. The code worked, so the useful part must have been in there somewhere. But it sure wasn't easy
According to all the latest reports, there was no truth in any of the
earlier reports.
Given that (Score:2)
C++ is more or less a superset of C (give or take a few minor issues [wikipedia.org]), why has regular C continued to thrive?
Re:Given that (Score:1)
Having used both extensively, I can tell you that it is much more difficult to write slow, bloated, overly complex code in C than in C++. It keeps you honest in that way. Also, most of the good things of C++ such as object-oriented programming and templating can be done at a basic level in C. For example, in C++, a class function is just an ordinary function with a hidden pointer to a (class) structure. Why not just pass in a pointer to a class structure in C? And class member privacy can easily be a matter of naming convention rather than something the compiler enforces.
C++ has its value, and may be better suited for building large, complex, systems such as GUI frameworks, but C is a great choice for cases where speed and minimal size are paramount, such as most embedded code as well as the Linux kernel. In principle, it's possible to write fast, small code in C++ by using its features selectively. However, if you do that, you're left with mostly just the features you could have emulated in C anyway.
Oh, and did I mention that in its current form C is the "perfect" programming language? Other languages have their own goals, but judged in terms of its own goals, C does what it's trying to do better than just about any other language - far better than C++ meets its goals. There's a reason that changes to C over its many years have been very minimal, and virtually always for the better.
Re: (Score:0)
>For example, in C++, a class function is just an ordinary function with a hidden pointer to a (class) structure. Why not just pass in a pointer to a class structure in C?
GNOME does this. It's great for everything except writing concise, readable C code. They have a language on top of this called Vala, which uses GNOME's type system (and in fact compiles to C) but without having to write complex object and type initialization code. But AFAIK not a lot of people use it.
Re: (Score:1)
It's been ages since I read Stroustrup or Kernighan & Ritchie, as I have largely moved on from embedded/Unix programming into Web based systems but I seem to recall one of the arguments for using C++ was that it could always do things as efficiently as C and possibly more so.
Re: (Score:1)
Likely true, but the benefit of C that I'm highlighting is that it gives you very little rope to hang yourself with in terms of creating a system composed of layer-upon-layer of classes. In contrast, I once worked with someone who loved to create class-upon-inherited-class for the simplest things in C++. Everyone who looked at his code wondered "where's the beef?", that is, the part that did something useful. The code worked, so the useful part must have been in there somewhere. But it sure wasn't easy