Interview with creator of C++

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

hooflung

Golden Member
Dec 31, 2004
1,190
1
0
C has OOP ideas in it. A C struct is surely the first C OOP concept. It is what the C++ class is based off of. A class is a struct that allows functions with user-defined visibility. C actually allows functions in a struct too but they are all essentially public and have to be function pointers iirc which isn't exactly elegant to some.

As for why C++ is still a debated topic I think it is because C++ doesn't have any standard for matrices. C++ strictly speaking in C++03 implementations, not compilers with future-looking features of C++0x, have restrictive unions.

C++0x is essentially C++ and some Boost or Boost Like libraries and some other programmer wants like enhanced polymorphism, hash tables and unrestricted unions.

Though I think if you asked any C developer, especially from the Linux Kernel Dev teams they would ask you why anyone would bother especially since the embedded programming is all the rage. I guess if you are a iOS developer you'll already be on Obj.C and all its pro's and cons. But for the rest of us, a lot of times you can write a program in C even though people would swear it would have been better to write in C++ because of classes and STL. Though they couldn't answer you why that is... it is just some C++ developer assumption.

And there lies the problem... C++ has a lot of developers who don't know why they use C++ over C. It was just their CS instructors banged OOP down their throats and that C++ is faster than Java. Well that may or may not be true, depending on what you are trying to do. Especially if the compiler has to figure out how to express the return value type of some Template where as another language, VM or not, had a native data structure for that specific type.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
C has OOP ideas in it. A C struct is surely the first C OOP concept. It is what the C++ class is based off of. A class is a struct that allows functions with user-defined visibility. C actually allows functions in a struct too but they are all essentially public and have to be function pointers iirc which isn't exactly elegant to some.

As for why C++ is still a debated topic I think it is because C++ doesn't have any standard for matrices. C++ strictly speaking in C++03 implementations, not compilers with future-looking features of C++0x, have restrictive unions.

C++0x is essentially C++ and some Boost or Boost Like libraries and some other programmer wants like enhanced polymorphism, hash tables and unrestricted unions.

Though I think if you asked any C developer, especially from the Linux Kernel Dev teams they would ask you why anyone would bother especially since the embedded programming is all the rage. I guess if you are a iOS developer you'll already be on Obj.C and all its pro's and cons. But for the rest of us, a lot of times you can write a program in C even though people would swear it would have been better to write in C++ because of classes and STL. Though they couldn't answer you why that is... it is just some C++ developer assumption.

And there lies the problem... C++ has a lot of developers who don't know why they use C++ over C. It was just their CS instructors banged OOP down their throats and that C++ is faster than Java. Well that may or may not be true, depending on what you are trying to do. Especially if the compiler has to figure out how to express the return value type of some Template where as another language, VM or not, had a native data structure for that specific type.

There are several aspects which C++ shines over C (and visa versa with the new C standard).

You mentioned one of them, the class. Just saying "This is private" and "This is public" really does prevent a lot of problems. Not only that, but function pointers associated with the class also removes many hassles (You don't have to pass in a reference of the object to the function every time you want to use it). Seriously, there are major benefits of C++ for developing.

Templates can be a huge boon as well. defining general characteristics functions/objects/data structures and then using it for multiple types is amazing. For example, lets say you wanted to sort an array of ints, shorts, and strings. With C that in tails writing a sorting function for each of the data types you want to sort.

Now, you say "Especially the kernel developers" and honestly those are, IMO, the last people you should ask about C vs C++. Seriously, Linus's big issue with C vs C++ is that he though operator overloading was too complex and that *GASP* two objects might share a function with the same name which might be confusing! Two of the most ridiculous claims against c++ I have ever heard. That being said, the kernel in particular is well suited for a lower level language. Most of the operations are things like "If signal a comes from component b send message b to component d". Lots of boring cause/effect programming. Not only that, but the modularity of C++ might actually hurt the kernel just for the shear fact that each component in a PC is fairly different, so having base classes which have sub-devices based on them could be damaging when component fundamentally behaves different from another (IE one video card to the next).

But programming a game? I can only imagine the fresh hell it would be to use C entirely for something like that. Games benefit so greatly from object oriented programming its hard NOT to see how C++ is better than C for this. Things like polymorphism really work wonders when you are describing different elements of a game. That, and the natural decoupling that happens when you OOP is fantastic for making sure one part doesn't break the other. You can literally have one person work on the rendering engine, another on the sound, and another on the AI independently, whereas with C something like that would not be fun as you would have to know what is going on in each instance to make sure you aren't breaking anything.

Now, I'm not saying that there is no case for C, I am saying, however, that there are genuinely good cases for using C++ which C just doesn't make a good choice. All and all, either could do the others job in any situation, the question is which is the better fit.
 

hooflung

Golden Member
Dec 31, 2004
1,190
1
0
Sure, the legitimacy of OOP is not in question, especially in context of application development being games or not. The problem with C++ is when people either use it out of its modus operandi or they rely on 3rd party libraries that fill in the gap where C++ doesn't, such as matrices.

Also, let us be fair to Linus. He hates C++ not just because of what you described, but because he hates C++ developers because they are typical idiots in the OSS world soap boxing concepts they truely don't understand. Out of his own mouth in regards to the Git development mailing list. http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918

Now, C++0x was just a glimmer in the eye's of ISO but there is a lot of validity to what he and others say, especially in the context of something so file intensive as Git. They also go on to condemn C++ because it wasn't that advanced enough over C to grapple what they believe to be next-generation concepts in compiler/language such as garbage collection. Saying C++ was wasting time fixing things they shouldn't fix and ignoring things they truely wish C had.

In that context I don't think you'll find much of an argument.

I don't think you will find them arguing that C++ classes can't lead closed source projects into the golden land of re-usability. They would only be destroying their credibility if they made such claims.

I think it all comes down to the project. I know it is cliche to say, "Right tool for the right job," but I think if you start from scratch you should think about maintainability. If you don't need classes then why you using them? Functional programming isn't dead, just like key-store and map-reduce ideals aren't dead with the advent of relational databases. In the same veign if what you are writing leverages well against classes then you'd kinda be a fool to not use them.

I could care less about people hating C++ because they think associative arrays should be as native as a char vs being part of the STL. I think it was a shame that the STL didn't include matrices but v0v. These days I think it is rare for you to find C code unless it is a game on a console where its all written with bare metal functions ( when does this happen anymore besides the DS? and some smartphones? ) unless you start looking at projects like Git where its 100% C because it doesn't need anything from C++ because the 3rd party libraries were deamed too 'expensive' or 'messy' to bother.
 
Last edited:

hooflung

Golden Member
Dec 31, 2004
1,190
1
0
To be more clear, the
The problem with C++ is when people either use it out of its modus operandi or they rely on 3rd party libraries that fill in the gap where C++ doesn't, such as matrices.

Should have been more clear. Their is no problem with C++ in itself, but the contention with C vs C++ vs Neckbearded Developers usually come up when these are the topics of debate.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
To be more clear, the

Should have been more clear. Their is no problem with C++ in itself, but the contention with C vs C++ vs Neckbearded Developers usually come up when these are the topics of debate.

Well. For most part I agree with you, right tool for the right job. I do sort of disagree with the "Its a failing of C++ that it has to rely on libraries", in my mind, that is one of the greatest strengths of C++. Unlike java or C#, you don't have everything including the kitchen sink in the language, rather it is the bare minimum (this is really a strength of C as well). It is a shame that the STL didn't go far enough to implement matrices, it really should have (no-one wanted to?). The use of libraries is a perfect example of code reuse in action.

The big failing with C++, IMO, is that it didn't describe some sort of standard calling method. And worse, IIRC it didn't describe a standard class passing method. This makes making C++ library for VC and GCC next to impossible, you end up having to have to different versions for the same library.

But again, right tool for the right job. I agree, C++ shouldn't be used everywhere. In fact, C like languages shouldn't be used everywhere (but they can be used pretty effectively in 97->99.9999999% of cases). Right tool for the right job and all.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I guess if you are a iOS developer you'll already be on Obj.C and all its pro's and cons.

There are pros?

As for Torvalds, seriously, the guy's place in the history of computing is secure and deserved. However, one continues to hope that as he ages he will learn to stfu.
 

hooflung

Golden Member
Dec 31, 2004
1,190
1
0
Technically Objective C wasn't developed by apple. It came from Stepstone. It is currently developed and owned by apple though which guarantees no one but apple will every use it seriously. Not with C++ and QT being good enough if you want cross platform elegance.
 
Last edited: