What makes C++ so powerful?

Started by
147 comments, last by CoffeeMug 17 years, 11 months ago
What makes C++ a powerful language, when not taking language or platform-specific frameworks (.NET, J2SE, MFC, etc) into account is that it has a lot of different features that can be used.

In particular, the following features are what makes C++ great:
-Templates. The ability to write type independent code gives a great advantage. Templates make it possible to write a piece of code once and then use it with many different types and/or other configurations without having to make abstractions or writing the same code many times.
-References. References give you the power of pointers with compile time sanity checking. The automagic referencing in Java seems a little awkward to me. Languages with no references or pointers need some way to pass data back and forth to procedures and functions, which is either done by global variables or moving lots of data back and forth to the procedure and it's caller.
-Operator overloading. This is a great feature. Together with templates, operator overloading makes some tasks a lot simpler, take std::sort for example. In game programming, it's convinient to have mathematical operators without doing something like Matrix.multiply(Vector). What I don't like is the way that they are used in C++ streams, but it's a matter of opinion.
-Object oriented programming, virtual functions, etc. These are pretty much in every other language too. But worth mentioning, tho. On the other hand, OOP makes bad programmers' code even worse, when they start using overkill design patterns for simple tasks.
-It compiles into native code. 'nuff said.

Things that could have been done better in C++:
-Interfaces. There are no Java-like interfaces in C++. You can use multiple inheritance, but that is much much more complicated than using interfaces in Java.
-The fact that C++ standards are relatively young. C++ is constantly evolving, even the most basic features of the actual language, not just STL and other frameworks surronding it. This is frustrating, because you will have to learn new features of C++ as it develops. On the other hand, the new standards are backwards compatible, and thus they may suffer from some legacy stuff compared to all-new languages and environments.

Some bad things about C++ when taking platform and/or language specific frameworks into account:
-The lack of a standard framework. The amount of standard C++ stuff is very little compared to Java, for example. There is STL providing some neat stuff, tho.
-The need of using C code. You will most likely need to use various different libraries when doing a project. Most of them are C-only. Some people (IMO) waste a lot of time wrapping C into C++.
-Using different libraries doesn't give you that consistent API and naming convention there is in Java, for example. Of course there is the OpenGL-like naming movement (OpenAL, DevIL, etc). Windows and MFC users have adopted the hungarian notation and naming convention, which gives some consistency, tho.

There really isn't anything good what I can say about C++ and it's frameworks. I have not used MFC, because it's windows-only, I have no experience of DirectX, either. They might provide a nice and consistent API for windows programming (or then not).

The problem with Java is that it was designed badly in the first place. There is no operator overloading, no templates and the automagic referencing is pretty strange. And when it comes to the framework, the awful AWT of Java 1.x and it's legacy in the more recent versions have caused me a lot of premature hair loss. There is a lot of deprecated stuff in the Java framework, which have not been removed and are unlikely to be removed in close future. This makes the java framework a bit bloated and slow.

I have never used C# so I can't compare C++ to it. I've heard it's pretty good, tho. I can't compare .NET to other frameworks either.

What I am currently into is Python. I like programming with it, because it gives me a lot of freedom. On the other hand, the freedom I get is away from the power of C++. I like the syntax, too. Less {, [, ], }, ( and )-charactes needed and it's still readable.

This is my opinion about the matter. I hope I don't inflict a flame war on the subject. I have a bad habit of doing that.

-Riku

Advertisement
Quote:Original post by Zyndrof
Hmm... Whenever I start to feel that I have a little hang of this programming thing, more questions comes to mind and more answers makes more questions :P

I recently won a book on VB.net and am trying to decide if I should focus on C++ at the moment or start VB.net instead. It's hard not to use the book that lies waiting in the shelf :/

If my long-time goal is to start (or at least try) game programming, would VB.net be an alternative? The thing is, if I like doing game programming, there shouldn't be any problem switching to a more suitable language for the task. But if I find out I don't like it and want to stick with regular applications, what are the pros and cons of C++ and VB.net?


In the long term, it won't make any difference. In the short term, C++ has a steep learning curve, so another langauge might be better suited for beginners. But as I said, once you've got started, it doesn't matter either way. It won't be a handicap in the long term that you started with something other than C++, that's for sure. So basically, don't worry. Pick a language at random, and try to learn it. [smile]

Quote:
Spoonbender, I have to disagree with you there, having direct control over memory and the use of pointers gives C++ a huge advantage over other languages. You might not use this but a lot of us do.

What do you use it for? Is it something that couldn't be done in Java or C#? Do you actually *need* "direct" (although as was mentioned earlier, this is an illusion) memory control? The only time you *need* this is when writing low level drivers or kernels and similar. For everything else, you *could* just let the compiler handle memory management, if you used a language that allowed it. (Of course, in some circumstances this might be slightly slower, but that's not important here. I'm just pointing out that you don't *need* this low-level control)

Of course you use it as long as you're programming in C++, because C++ doesn't really offer a framework that can handle it for you.
If you were working in C#, I doubt you'd *need* it.
If you really disagree with me, then show me a program in C++ that couldn't have been made using C#.
Quote:Original post by Spoonbender
If you really disagree with me, then show me a program in C++ that couldn't have been made using C#.


An operating system? You would need a C# compiler that compiles to native binary, and to the best of my knowledge there aren't any...

I think its more of a question "what language not to pick". The only language of all the ones ive tried that I wouldnt recommend using is VB (not .NET), VB is getting old, isn't supported by MS anymore and so on..

I'd suggest starting with a fairly young OO language like Java or .NET(C#, VB.NET,...), once you get a hang of these it will be easier to switch to C++ if you will ever feel the need to.
Quote:Original post by RichardoX
In particular, the following features are what makes C++ great:
-Templates.
-References.
-Operator overloading.
-Object oriented programming, virtual functions, etc.
-It compiles into native code.

None particular to C++. None exceptionally implemented in C++. I remember reading in an old issue of The C++ Report a comment by someone credited as the "inventor of templates" to the effect that, "When I invented templates, C++ was not what I had in mind." Admittedly, C++ has undergone significant revision since.

Fundamentally, there's nothing special about C++. It's a powerful language, but not significantly more so than dozens of alternatives. It's an efficient language, but it doesn't exactly blow the competition out of the water (and it lags badly in certain contexts). It's feature-rich, but mostly in comparison to C. What's really special about C++?

Legacy. It piggy-backed on C, which had enjoyed immense popularity as the first portable systems programming language. C++ is too verbose and large to be a systems programming language (unless you restrict yourself to a subset), and too arcane and under-powered to serve as a contemporary applications programming language. The Standards Committee knows this, so look for some significant enhancements/revisions with the next standard (or just take a look at some of the current drafts).

Quote:Original post by Oberon_Command
An operating system? You would need a C# compiler that compiles to native binary, and to the best of my knowledge there aren't any...

THere weren't any native C++ compilers once upon a time, either, but they were written.
I remember when I was first starting out. I played around with Quick Basic *shivers*, then went up to Pascal, learned C and finally C++. All the while only programming games. Along the way I played around with other languages as well such as FORTRAN, LISP, Object Pascal, and Visual Basic... Once you get the concepts of programming down, then you should be able to pick up a book or some documentation and put another language on your belt. Each language has it's own positives and negatives. The whole idea is very subjective so I won't try to tell you what is better. But if you're just starting out I would suggest something simple such as C# or Java since you can get something to show for your efforts very quickly. So, have fun learning.

-Dagbud
Edmund Weese7-bit Games
Okay, I feel me questions have been answered and I will give .NET a shot and see how it works for me. I will also try to get into C++ in school (they have a course which demands you to have read another programming course which I haven't).

Thank you all for your help, and I promise I will try not to think about languages and instead think about programming :P
Quote:Original post by Oluseyi
I remember reading in an old issue of The C++ Report a comment by someone credited as the "inventor of templates" to the effect that, "When I invented templates, C++ was not what I had in mind." Admittedly, C++ has undergone significant revision since.


Oddly enough, the same thing was said by Alan Kay about OOP. :)

Quote:
Legacy. It piggy-backed on C, which had enjoyed immense popularity as the first portable systems programming language. C++ is too verbose and large to be a systems programming language (unless you restrict yourself to a subset), and too arcane and under-powered to serve as a contemporary applications programming language. The Standards Committee knows this, so look for some significant enhancements/revisions with the next standard (or just take a look at some of the current drafts).


QFE.
C++ is good if you really need to squeeze those last cpu cycles out of your system. I.E. We use it here at work to model Electronic Warfare tools. Something that C#, java or whatever, can't even touch with a 10 foot pole... of course, if the algorithm is effeciant and you don't need that level of performance all the other languages are more than optimal these days... I wouldn't write another GUI in C++, I would use C# or Java or something... they have greate interopability (sp) these days... I would rather spend time working on my game than writing GUI code in C++ ( shiver )...

Game in GDS
Quote:Original post by RichardoX
The problem with Java is that it was designed badly in the first place. There is no operator overloading, no templates and the automagic referencing is pretty strange. And when it comes to the framework, the awful AWT of Java 1.x and it's legacy in the more recent versions have caused me a lot of premature hair loss. There is a lot of deprecated stuff in the Java framework, which have not been removed and are unlikely to be removed in close future. This makes the java framework a bit bloated and slow.

I have never used C# so I can't compare C++ to it. I've heard it's pretty good, tho. I can't compare .NET to other frameworks either.


This is the usual unbacked claim here in gamedev.net . People assume C# is better because of emotional appeal, maybe the 'C' in the name makes them feel better about it. It gives some impression that's a sequel to C++, doesn't it?

I think what nobody mentions about Java is that ALL methods and classes that are deprecated are marked so, the IDE will warn you about them, and the Javadocs tells exactly what to use instead. Unless you have VERY good reasons for using them there's no need to use it, and that wouldn't make Java slower either.

I can't really understand why anyone trying to find something "to talk about Java" touches this subject. Any project manager could tell you how much the developer hour cost and how much budget you have available for making things to work. So, would you prefer to rewrite your application, and sometimes redesign it, because of "no backward compatible changes" from one version to another?

An average Joe could see this and be eager to type:

"But why would anyone want to update to a new version!? Couldn't I just choose which one to use?"

- Performance updates;
- Library updates that bring new features for using in your projects that save LOTS of time (like the concurrent utilities in Java 5);
- Language updates;
- Bug fixes;
- etc.

They will need to clean that up one day, but radical changes are not good, except if you are Microsoft and your monopoly makes developers endure the pain or if you are an open source developer whose projects are a mess.

This topic is closed to new replies.

Advertisement