Advertisement Jump to content
Sign in to follow this  
traghera

Why C++?

This topic is 1785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 So I dabble with programming, and I know some C++, C# and a little about java/javascript and HTML, and while searching around I frequently found people that say that "real game programmers" use C++ for game programming. However from what I gather even if that seems to be true, there are a lot of other programming languages, perhaps even more suitable for game programming.

 

  So then I happened upon somewhat of a dumb but meaningful question:

         Why C++?

What makes C++ the favorite/mainstream language in game programming, when other languages such as C# or javascript are easier? Is it just because C++ has been around longer? Does it offer more control over some aspects of data-storage and such? Does it simply have more support?

 

Thank you in advance for answering.

Share this post


Link to post
Share on other sites
Advertisement

I think there arent many choice there!

If we count there are only java,C++,C#,Python, Delphi... Java is only good for their embedded type, run well on many platform. But i think they are not fast as C++ and they are not very direct (in means of directX...). I worked alot with java, for server and j2me!

 

I'm not a master of C#, code couple of samples... They are very good for tool, windows app... that need good UI. The code is a lot easy and clear than C++ but they still work behind something (virtual machine???) like java. But I think it's very close compare to C++.

 

But even other lang is good for game, C++ is still superior because of the documents/samples/tutorials on the net, most of them are on C++ ! But using engines like Unity can save us a lot of time learning langs, they can export into many platforms (web,ios,pc...). Just learn the script is sometime enough (not all the time)!

Share this post


Link to post
Share on other sites

I recall one of the issues with some of the languages listed (versus C++) is you dont have tight control of garbage cleanup.  You leave it to the default and it kicks in whenever it feels like it.  You control it and now you have to do alot of work because of the standard paradigm of programmer used to leaving it to automatic OR you program as if there is no automatic and you might as well be using C++.

 

Performancewise anything that uses a virtual machine will be slower.  Can a JIT compiler be anywhere as good as a full blown dedicated native compiler ? and games do weird stuff the JIT might not be so great at optimizing (you can find the debates elsewhere).

 

I dont know if there is any need still to go to assembly code for critical chunks of code (that once was true).

 

Scripting languages ARE used for certain tasks and you would probably have to ask project manager what total coding line counts are used these days  between the non-scripted (C++) versus scripting like LUA, etc...

 

Another factor is how old are the key architects of these games?  Which languages were mature when they reached their highest coding efficiency (besides the other issues already mentioned)

Edited by wodinoneeye

Share this post


Link to post
Share on other sites

 So I dabble with programming, and I know some C++, C# and a little about java/javascript and HTML, and while searching around I frequently found people that say that "real game programmers" use C++ for game programming. However from what I gather even if that seems to be true, there are a lot of other programming languages, perhaps even more suitable for game programming.

 

  So then I happened upon somewhat of a dumb but meaningful question:

         Why C++?

What makes C++ the favorite/mainstream language in game programming, when other languages such as C# or javascript are easier? Is it just because C++ has been around longer? Does it offer more control over some aspects of data-storage and such? Does it simply have more support?

 

Thank you in advance for answering.

The reasons we use C++ are mostly because it allows access to program nearly to the metal, and take advantage of all hardware acceleration or talk directly to the hardware.

The other reasons are legacy as we moved away from assembler towards C so in the past we made another switch from C to C++ so that we could take advantage of Object Oriented programming features of the language. All these steps were made to make programmers more efficient but not lose the access to hardware and memory management and tight control over what the code is doing as Danicco points out.

 

Most tripple A companies still dont use modern C++ features, generally C++ is used as C with Classes. Templates, STL containers and such are preferred to not be used. Neatly all C++ exceptions are turned off in favour of error codes in most game engines.

Edited by NightCreature83

Share this post


Link to post
Share on other sites

The simple answer is C++ saves me time. Being close to the metal is nice and all, as is control of freeing memory, but I'd drop those features in a heartbeat if there was a language with better development tools and libraries available for game programming than what exists for C++. The success of XNA+C#, until Microsoft abandoned it, demonstrates I am not alone in that attitude. C# was taking significant market share away from C++ for games development due to the strength of tools available.

Share this post


Link to post
Share on other sites

Well, theres a reason why OpenGL and DirectX are implemented in C and not C#.  If you want maximal efficiency, you have to be close to the hardware.   C is pretty much the only popular systems language left.   By systems language, I mean something that has a fairly predictable translation to machine instructions, basically something you can use to write an operating system or hardware interface.   The only thing lower are assembly (which is non-portable and very difficult to write) VHDL and Verilog, which describe hardware but not abstract it.

 

C++ is basically C with OO attached.  You are free to use any C function, and many do. 

Which is party of the problem and why C++ is unfortunately, quite defective.  Here is a summary of the arguments http://yosefk.com/c++fqa/defective.html  

 

To get around the deficiencies of C++, many completely omit the OO features of C++ (such as not using virtual functions, using trivial constructors/destructors and calling manual initialization and shutdown routines) At which point, you lose all the benefits of OO anyway, pn top of which you have a bunch of useless, extra code.   I like to call this "C++--"  In many cases, I also encounter what I consider to be lazy design patterns such as the singleton and factory which breaks OO methodologies (inheritance and the idea of reusable code), which again, leads one to question why we are using OO in the first place. 

 

About the only good thing with C++ are the typesafe containers implemented in the STL.  Still, I fiind them overally verbose when using the iterators and the code just looks ugly.  Here's a gem from Ogre code I wrote a while back:

 
std::vector<MovableObject*>::const_iterator it = movingObjs.begin();
std::vector<MovableObject*>::const_iterator end = movingObjs.end();
while(it != end) {
      MovableObject* movableObject = (*it);
// do somethign with the movable object
      ++it;
}
Tell me how that is better than something like
 
 
for(int n=0; n<movingObjects.size; n++) {
      MovableObject* movableObject = movingObjects.objs[n];
// do something with the movable object
}
 
Assuming I have a proper movingObjects struct (not class) hich has the appropriate fields.
Edited by SunDog

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!