Jump to content

  • Log In with Google      Sign In   
  • Create Account


Why is C++ the industry standard?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • This topic is locked This topic is locked
38 replies to this topic

#1 stein102   Members   -  Reputation: 475

Like
2Likes
Like

Posted 23 May 2012 - 09:09 PM

I've seen a billion C++ vs. X-Language posts and the answer is always, whatever you prefer to code in is the better language. But what I want to know is; why is C++ the industry standard for game programming? Almost every reputable game company uses C++ for their games. What is so special about C++? I've never gone too deep in C++, I've picked up the book Accelerated C++, but I just can't seem to get the hang of it and I've always gone back to Java. Now I'm thinking of trying another C++ book, but that's getting off topic.

Thanks.

Sponsor:

#2 Washu   Senior Moderators   -  Reputation: 5047

Like
2Likes
Like

Posted 23 May 2012 - 10:00 PM

Because it works on all the platforms a game studio needs to target. Specifically: Xbox 360, PS3, and sometimes PC.

Its not a matter of a "want" to use C++, but a matter of "what is required to operate on this platform?"

That being said, indie developers can use XNA to target the Xbox 360 platform, with limitations of course.

Edited by Washu, 23 May 2012 - 10:01 PM.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX


#3 Jebbs   Members   -  Reputation: 280

Like
0Likes
Like

Posted 23 May 2012 - 10:19 PM

Another common reason is for performance.
For some things, c++ can be faster than another language. That said, this isn't as good of a reason these days what with a lot of people being able to make games in x language and still get decent performance.

A third reason could be that it's been around a while and has a pretty big community and a lot of libraries for so many different things, as well as tons of documentation, tutorials, etc.

#4 nife87   Members   -  Reputation: 516

Like
2Likes
Like

Posted 24 May 2012 - 12:01 AM

Also that existing (huge) code bases / libraries were in C and all the programmers knew C, so the change from C to C++ (which can be made in steps, since most C also works in C++) must have been easier than the alternatives. Just a thought, though.

#5 szecs   Members   -  Reputation: 2121

Like
0Likes
Like

Posted 24 May 2012 - 12:46 AM

Because it works on all the platforms a game studio needs to target. Specifically: Xbox 360, PS3, and sometimes PC.

Its not a matter of a "want" to use C++, but a matter of "what is required to operate on this platform?"

That being said, indie developers can use XNA to target the Xbox 360 platform, with limitations of course.


Does it mean that only C/C++ has compilers to all platforms? Why there isn't any compilers written to all platforms in other languages? Maybe there's not strong enough demand for that?

#6 SimonForsman   Crossbones+   -  Reputation: 6067

Like
1Likes
Like

Posted 24 May 2012 - 01:53 AM

Does it mean that only C/C++ has compilers to all platforms? Why there isn't any compilers written to all platforms in other languages? Maybe there's not strong enough demand for that?


Most popular languages get compilers for all platforms eventually.

The problem really is that C and C++ are the de-facto standards, existing middleware, engines, etc are allready written in them and those will not get ported over that quickly(maybe not at all) if they have to be rewritten from scratch in a new language. This in turn means that a game platform without a C and a C++ compiler will fail miserably. (WP7 is a great example of what happens if you don't support native C++).

Since C++ almost has to be supported it is one of the few languages that a middleware writer can count on being supported on launch on a new platform which makes it the safest language to write new middleware in which keeps the cycle going.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 Olof Hedman   Crossbones+   -  Reputation: 2768

Like
0Likes
Like

Posted 24 May 2012 - 02:27 AM

Another common reason is for performance.
For some things, c++ can be faster than another language. That said, this isn't as good of a reason these days what with a lot of people being able to make games in x language and still get decent performance.


The reason you can do things with decent performance in x language, is because someone implemented low level library functions for what you wanted to do.
Usually implemented in C++ or C.

#8 Zlodo   Members   -  Reputation: 237

Like
1Likes
Like

Posted 24 May 2012 - 02:35 AM

Most popular languages these days insist on runnning in a VM even though the benefits for video games are questionable compared to their runtime cost.

Few languages are designed to be compiled natively while still offering a diverse set of high level paradigms such as OO programming, meta programming and functional programming. There's basically mostly C++ and D that fit this category. Only one of those two is a mature language with a proven design and a huge ecosystem of tools, compilers, libraries, and frameworks.

Template meta programming in particular allows C++ to combine very good runtime performance with very good abstraction capabilities. There's pretty much no other language that have both of those things along with a big ecosystem.

Edited by Zlodo, 24 May 2012 - 02:35 AM.


#9 saejox   Members   -  Reputation: 714

Like
-3Likes
Like

Posted 24 May 2012 - 05:41 AM

it has a little thing called "pointer"

#10 Antheus   Members   -  Reputation: 2397

Like
0Likes
Like

Posted 24 May 2012 - 06:48 AM

whatever you prefer to code in is the better language.


It is.

Over time, you then want to do more. And inevitably, no matter the language, you hit roadblocks. They may be big or small, related to performance, management, refactoring, overall development speed, platform support, open/proprietary issues, third-party library availability, ....

Then one looks around and realizes the choice of languages that can work around any of these is fairly limited. It's almost without exception C or C++.


Companies do not have time or budget to experiment. So they start with one thing which is designed to not have limitations.

Electric cars are fine. But if you want something that will work everywhere, you buy something that runs on gas.

#11 Bregma   Crossbones+   -  Reputation: 5054

Like
10Likes
Like

Posted 24 May 2012 - 07:56 AM

C was developed in the late 1960s to make systems programming easier. It's head-and-shoulders above using assembly language directly. It succeeded over competing languages such as COBOL, FORTRAN, or Algol/Pascal because (a) most Unix systems came with an essentially free compiler, and most institutes of higher education had Unix systems of some description, so professional programmers were exposed to it and found it powerful and expressive, and (b) it lacked all the restrictions that made the other languages 'safer' at a high cost of CPU and memory and it was 'closer to the metal' in its abstract machine. C had the 'register' keyword, COBOL had PICTURE(99) -- which resembles how a computer operates more?

Along comes the era of the personal computer. For a while, Pascal and BASIC reigned supreme: the Apple ][ came with Microsoft BASIC as its OS shell. The Macintosh was programmed in Pascal and all its system call bindings were provided in Pascal and assembler. The PC was mostly either BASIC or assembler. Then Microsoft released its toolchain for free in an attempt to win developers to its platform (at the time there was an open market and strong competition, and Microsoft was merely just another player). You could download and install Microsoft Visual C and start being productive immediately in a way that you could not in assembler, although BASIC was still in widespread use. Because the overhead of BASIC was high and you had to ship source, C eventually became the de facto standard for developing on the PC, and soon on the Macintosh as well. Over the last 20 years, most infrastructure was built using C.

Meanwhile, on the big metal side, C was proving to be unwieldy for large non-systems projects such as simulations. Several attempts to make a 'better C' were made, usually borrowing concepts that were being explored in academia at the time. Among these attempts were Objective-C and C-with-classes. C-with-classes had the philosophy that (a) it should be fully and completely backwards-compatible with existing C, making migration and combination dead simple and leveraging the existing code base, and (b) you should only ever pay for a feature you use. C-with-classes evolved organically over the years into C++, and was adopted on its merits alone without a single corporate backer, marketing department, or salesforce.

Come the turn of the century, and the single language of choice for programming on the Macintosh was C++. The default language for software development on the PC was C++. Entire desktop systems for Unix and Linux systems were written in C++. An international standard for the language was established in November of 1997 and a number of commercial vendors produced supported compilers, and there were well-known free compilers available for pretty much any platform, including embedded. At the same time, a number of commercial ventures designed their own languages and tried to sell them as solution in order to capture a share of what could potentially be a lucrative market of only they could fence of a part of the commons. Much money was spent by corporate backers and salesforces, including convincing educational institutes to limit their students exposure to certain products in exchange for other advantages.

Most of the proposed replacements for C++ as the de facto programming language were hailed by their creators as being superior because they avoided some set of problems (real or perceived) that could be attributed to C++. Inevitably they did so either by removing the ability of a programmer to accomplish some task, or by increasing the runtime cost of unrelated features. C++, even in it latest incarnation, allows the programmer total freedom to do what they need (at the cost of potential errors if done wrong), and still only makes you pay for the features you use.

So, why has some commercially-developed silver bullet not gained a monopoly position in the programming world? I can't be sure, but I've been programming for quite a few decades. I've seen a lot of solver bullets promoted by a lot of commercial interests, and each and every one solves some problem, gets you to about 80% of your goal, and then requires you to resort to good old C (or might as well use C++) to let you finish the task. Turns out you might as well just bite that bullet, learn how to use the tool you're going to end up using anyway, and stick to that. Who knows, maybe next year some startup will have a business plan that really will solve all out technical problems.

tl;dr C++ lets you do stuff the alternatives don't, it lets you directly leverage existing infrastructure, and it lets you pay only for language features you use. No alternative does all that.
Stephen M. Webb
Professional Free Software Developer

#12 frob   Moderators   -  Reputation: 20514

Like
0Likes
Like

Posted 24 May 2012 - 11:28 AM

I've seen a billion C++ vs. X-Language posts and the answer is always, whatever you prefer to code in is the better language. But what I want to know is; why is C++ the industry standard for game programming? Almost every reputable game company uses C++ for their games. What is so special about C++? I've never gone too deep in C++, I've picked up the book Accelerated C++, but I just can't seem to get the hang of it and I've always gone back to Java. Now I'm thinking of trying another C++ book, but that's getting off topic.

It all depends on your target. When it comes to devices by number, the three major consoles (Sony, Microsoft, Nintendo) are actually the exception to the rule.

If you develop on Android you don't use c++; you use Java. If you developed on older phones, such as the Nokia family, you developed in Java.

If you develop web games, up until recently there was a good chance you would use Java or Flash. Now there is a good chance your new applications will be developed with JavaScript and HTML5.

If you develop iOS games you use Objective C.

If you develop PC-only games you are more likely to develop in Java or C# than you are to develop in C++.

If you develop with an engine like Unity3D you can develop in C#.

In fact, at EA we use mono and custom library wrappers to develop in C# for not just PC but also for the three major consoles. Many major AAA cross-platform games are developed in C#.



C++ in games is on a downward trend. It won't go away any time soon, just like we see many SDKs provided in pure C, but the three major console makers are very much aware of the shift away from the language. It won't drop soon because you can call the functions directly through interop from any language and there is no incentive to rewrite their libraries.

With the next iteration of hardware I fully expect the SDKs for all three to provide support for C#; Microsoft already does, third party vendors already do it, and major game studios already do it.
Check out my personal indie blog at bryanwagstaff.com.

#13 frob   Moderators   -  Reputation: 20514

Like
0Likes
Like

Posted 24 May 2012 - 11:37 AM

tl;dr C++ lets you do stuff the alternatives don't, it lets you directly leverage existing infrastructure, and it lets you pay only for language features you use. No alternative does all that.

Nice theory, but completely false.

The whole point of object files is that you can call the functions from ANY language. You can call compiled Perl functions from C. You can call compiled Java functions from C#. You can call compiled C++ functions from Python. Etc, etc..

The only thing you need to know is the function's interface. Tools like SWIG can automatically convert them for all major languages. Other sites like pinvoke.net are specialized to C# or similar tools for JNI. Before the tools you had to do it manually but it was not a difficult task.

The barriers between languages has not existed for decades (since the mid 70's) when languages started compiling to common object file intermediate formats.

Edited by frob, 24 May 2012 - 01:11 PM.
Add pinvoke.net and JNI tools.

Check out my personal indie blog at bryanwagstaff.com.

#14 Ravyne   Crossbones+   -  Reputation: 7143

Like
8Likes
Like

Posted 24 May 2012 - 01:05 PM

You can give 101 technical reasons, ranging from true to false and covering every point in between, but the one true, fundamental reason is that C++ simply has inertia.

Assembler was the original standard, but was painful because of its lack of portability and cryptic nature. As software complexity increased and architectures became more diverse, a higher-level alternative was needed. Because, at the time, performance still mattered a great deal (because hardware was still slow, and memory was limited, especially on gaming machines), truly higher-level languages like Lisp, smalltalk and others failed to gain traction; it was C that provided just the right level of abstraction to maintain much of the performance of assembly languages, while making software easier to reason about and significantly reducing the pain of porting code from one machine to another. As software systems grew still larger and more complex, the less-cryptic-but-still-rather-monolithic C-style development practice started to show cracks, and still-further abstractions (OOP as implemented in C++) looked like a promising means to filling them. During the Assembly days, people threw out code and started over with each new architecture (one of the reasons that software systems remained small) so throwing it all out for something entirely new, that is, C, was not particularly jarring. But during the C days, people became more accustomed to *not* throwing away code (and so developed more and cleverer code), so being able to carry that code forward would be a major point in favor of any potential successor -- hence, we arrived at C++ rather than any of those other, now well-established, higher level languages like Lisp, Smalltalk, et al. We arrived at C++ because C was a suitable alternative at the time, and by the time we had realized C would only be a bridge to something better, we had already crossed too far to turn back and start fresh; it was easier to just continue on to whatever end C took us. We haven't transitioned away from C++ en masse, for the most part, because we are tied not to the language, but to the platforms that surround it, and because it is not so painful that an alternative is plainly necessary. Industries who are not tied to legacy platforms and code-bases have, in many cases, transitioned to easier (garbage-collected, etc) languages, but even many of those languages have a clear lineage with C and C++ because people-skills are a part of the "platform" too.

In short, C became the standard because it was the right solution at the right time, C++ became the standard because we were too attached to C to leave it entirely behind, despite its trappings, and C++ today *remains* the standard because it *is* the standard. Its a self-fulfilling prophecy at this point--or chicken-and-the-egg--There can be no alternative platform without an alternative language, and there can be no alternative language without an alternative platform.

Very luckily, C++ is not wholly terrible, and is indeed still quite malleable as C++11 shows. C++11 is perhaps not miles ahead in addressing the previous standard's warts, but it is significantly more ahead than a stones-throw (from a strong arm).

#15 freakchild   Members   -  Reputation: 557

Like
0Likes
Like

Posted 24 May 2012 - 05:14 PM

Ravyne that really is an excellent answer if you don't mind me saying. I was about to write my own explaining the whole Assembly->C->C++ history.

Really, C++ is the standard today only because of the link between all of those languages. The need for low level performance, the idea that C is a high level language, but one of the lower level ones really defined it as the next step from assembler and I think C++ was just the natural next thing in that chain. Most of the compilers we were using already did it.

Sometimes I wonder though what language we might have been using today if C never existed. What would've taken C's place in the interim? Pascal? BCPL?

Edited by freakchild, 25 May 2012 - 09:10 AM.


#16 Alpha_ProgDes   Crossbones+   -  Reputation: 4688

Like
1Likes
Like

Posted 24 May 2012 - 05:19 PM

it has a little thing called "pointer"

So does every language in existence.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#17 eugene2k   Members   -  Reputation: 237

Like
1Likes
Like

Posted 25 May 2012 - 02:25 PM

I've seen a billion C++ vs. X-Language posts and the answer is always, whatever you prefer to code in is the better language.

There's always the right tool for the job and the wrong ones. Comparing languages outside of the problem context is plain stupid. For game development the answer is simple: OOP is very fitting for writing game engines since a lot of things in a game engine can be represented as objects and C++ offers the best performance out of all of the OO languages.

#18 eugene2k   Members   -  Reputation: 237

Like
-4Likes
Like

Posted 25 May 2012 - 02:25 PM


it has a little thing called "pointer"

So does every language in existence.

Uhh... no?

#19 Dmytry   Members   -  Reputation: 1148

Like
1Likes
Like

Posted 27 May 2012 - 04:12 PM

What i believe is the case is that in practice the differences between high level programming languages are so tiny as not to warrant use of other language for any reasons beyond "that's what I know"; the C++ has libraries written in it. The few issues in C++ that other programming languages solve, are very minor comparatively to the rest of the complexities in the big software. Ultimately, the issues like 'managing the memory' or 'multi threaded execution', etc. are very difficult for beginners and are nontrivial in small projects, but are trivially tiny part of the job in a big project.

Other programming languages also tend to force preferred programming ideology of the author (functional programming, some vision of what OOP should be, etc), tend not to implement some pet hated feature (operator overloading is bad! overloading is bad!), or follow some unwieldly maxim (everything is an object!), to the detriment of actual fitness in general use outside the area of expertise of the designer of that programming language.

Edited by Dmytry, 27 May 2012 - 04:16 PM.

My game The Polynomial is now available on Steam. | The Polynomial homepage | Cloud and terrain rendering |Everything i said in that post is obviously ABSOLUTE TRUTH my unhumble opinion.

#20 phantom   Moderators   -  Reputation: 7156

Like
0Likes
Like

Posted 27 May 2012 - 04:37 PM

What i believe is the case is that in practice the differences between high level programming languages are so tiny as not to warrant use of other language for any reasons beyond "that's what I know"; the C++ has libraries written in it. The few issues in C++ that other programming languages solve, are very minor comparatively to the rest of the complexities in the big software. Ultimately, the issues like 'managing the memory' or 'multi threaded execution', etc. are very difficult for beginners and are nontrivial in small projects, but are trivially tiny part of the job in a big project.


Let me ask you something; how much time have you spent working with something like C#? And I don't mean "made a small program" I mean 'developed a sizable and complex system with it'?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS