views:

1034

answers:

7

What is the best language for programming a game project and why?

Why is the game programing world dominated by c++?

+3  A: 

Games are some of the most hardware intensive applications you can run. People program games in C++ for the performance, although there are a few games coming out nowadays written in C#.

This question has been asked before, check the following posts for more details: http://stackoverflow.com/questions/356068/viability-of-c-net-as-the-new-standard-game-dev-platform http://stackoverflow.com/questions/19642/suggested-gaming-platform-to-learn-direct-x-c-open-gl-or-xna

Stefan Mai
+1  A: 

If you use C++, you have a much larger codebase, although this shouldn't matter for most games (except 3D games or games that'll need libraries like physics engines). C# could be easier to write, depending on how much experience you have with it (or how much less/more experience you have with C++).

Also consider using some sort of game creation tool like XNA Game Studio or similar, they often can give you all sort of help with usual stuff.

schnaader
+15  A: 

This is kind of a difficult question to answer. For the most part, C++ is a "better" language for programming games in that it gives you so much direct control over memory management that you have more options to fine tune your performance. That, along with the fact that C++ has been around ages longer than C#, have lead to its current dominance in the game industry.

However, these days, with the .NET platform and C# becoming so much more mature, its not easy to rule it out as a very strong contender in the game programming arena. I think this is especially true for the near future, as .NET 4.0 and C# 4.0 will bring in a whole new era of multi-threaded and concurrent programming that could bring some massive performance gains to their platform. With multicore CPU's taking the desktop computing world by storm, and massively-cored CPU's only a short step behind .NET/C# 4.0, I think the ease of developing multi-threaded applications with .NET and C# 4.0 will give C++ a run for its money.

In the end, it will entirely depend upon how much control you think you need over memory management, and whether that control is worth the effort in the arena of massively parallel games. If you need that control, and think you can deal with the effort of writing a highly parallel game in C++, then you'll probably gain something from it. Otherwise, I would say C# 4.0 would be the better option.

jrista
May I add that if your goal is to go in the game industry (I mean : non-indie or on consoles) then your have currently no choice but to use C++. The XNA kit is not enough for most industry games.
Klaim
Also, don't forget that you can't use C# to program the PS3 or Wii (unless you use it as a scripting language on top of C++). So learning C# instead of C++ limits your employment options.
MB
It is also a lot easier to go from C++ to C#. C++ teaches you hardcore stuff like pointers and memory management. C# is a lot more like playing in a sand box.
MB
I see no reason why it wouldn't be possible to create a CLR for PS3 or Wii. Once C# becomes a major contendor for game development, I don't doubt that a new market will emerge for runtimes for C#. @Klaim: I don't see XNA as a factor in C# game development at all. On the contrary...once C# becomes a contendor, it will be engines from companies like ID, CryTek, etc. that will dominate. XNA is a sandbox in comparison to what will likely be written.
jrista
+3  A: 

It took years to get game developers off assembly onto C, then it took more years to get the industry onto C++. The reason is always the same ... "C will be too slow", "Objects will be to slow". There is enormous investment in code (engines, previous games, etc.) and talent in the industry in C++. It will take a long time for that to shift -- just as it has in the past. Someday, games will be developed in managed code, but it will take some time.

Meanwhile there are engines written for .NET in C#.

JP Alioto
Two more (commercial) XNA-based engines that are capable of producing impressive visuals:Visual3D.NET: http://game-engine.visual3d.net/Sunburn: http://www.synapsegaming.com/products/sunburn
JulianR
The showstopper for C# is that it is not a multi-platform language. You can't (for example) develop games for PS3 or Wii using C# only.
MB
@MB: Well. "managed code" does not imply C# or a single platform. You read something into my answer that's not there.
JP Alioto
+5  A: 

For commercial / bigger game projects, C++ is probably the best option. However, if you're thinking of doing smaller, indie type games, there's nothing stopping you going with C# or even Java.

I've done several small games with C++, and one with C# using the XNA Framework, mostly for curiosity. Currently I'm working on a platformer game using Java and LWJGL (Lightweight Java Game Library). And guess what? It's working absolutely fine, plus I get cross-platform compatibility practically for free! The reason I started this project with Java was to see if I could create a nice OpenGL-accelerated game using Java instead of C++ I've normally used. So far it's working very nicely for me, I was really suprised actually. =) To be honest I've become a bit tired with C++, coding in Java feels much more productive for me currently (big thanks goes to Eclipse IDE!).

So, for smaller games you can definitely have success with Java or C#, no need to bother with C++, unless you're doing something that needs 100% of the possible performance. XNA might be the easiest option to get started with, although as for myself I most probably won't be using it again since it's basically Windows only (plus Xbox 360)..

MH114
A game in Java? hmm... sure you can: Chess, Othelo, Platform 2D games, etc...
jpinto3912
*groan* If that's meant as a criticism, chess would actually be one of the computationally toughest games to do. Why else would IBM have built a specialised computer to play it?
CurtainDog
A: 

'Performance' is a red herring. Yes, games are just about the most demanding application that most consumers will run. However, most of the heavy lifting can be done with dedicated hardware, which will beat a software solution in any language any day of the week. The proliferation of Flash games should be proof enough that in most cases we have performance to burn (and now that we have some decent implementations I think we'll soon see games apearing in Javascript too).

I think it's just that many other languages are billed as business focused, or academic, or statistical, and developers on the whole haven't really felt the need to challenge those assumptions.

CurtainDog
Not if you want to develop leading edge games like Crysis, Half-Life, Grand Theft Auto etc. Development teams typically spend a lot of time optimizing the code, art assets etc. to make the game run as fast as possible. Especially on consoles.
MB
+2  A: 

I think you'll find that, when you create your own game, that being CPU bottlenecked (the only aspect on which language choice has any effect) is the last thing you need to be worried about. It's much, much easier to be bottlenecked by the GPU. Hell, with today's minimum of 2 cores, I would find it impressive if you even managed to ever reach 100% CPU usage because that would require a perfect workload division to utilize the 2 or 4 cores of the CPU.

Generally, it's much too common for me to run a game (presumably written in C++) to see it use at most 50%-60% of my CPU. And can you then really speak of a bottleneck with the language that you use, or a bottleneck of the algorithms used that don't allow you to scale across more than 1 CPU core? So even in a situation where you run into the limits of a single core, it's still possible to (theoretically) double your performance by optimizing your algorithms before you can truly say you're being limited by the language.

And this is only going to increase in the future with the advent of 8, 16 and 32 cores. You really don't want to have a game that's only capable of using only 1 core out of 32.

The real reason why C# isn't being used in the industry: there's no reason compelling enough for game studios that have invested a lot of money into their C++ code to switch to C#. Not just their code, but their developers are already very good in C++ so it would be odd to switch to C# for "ease of use" when that actually means a lot of new challenges to overcome and a lot of money to rewrite existing code. And after all that, you've got new code that's only supported on the PC (with Mono for Linux support) and Xbox 360. No PS3, no Wii. So you've just limited yourself for little gain.

JulianR
Even today, it is still the case that games are CPU limited. Sending state change and draw calls to a GPU takes up a surprisingly large amount of CPU time. Even today development teams for leading edge games still spend a lot of time optimizing the CPU.
MB
really, you are amazing and your view is satisfied.100:thans;goto 100;
mavric
what is your thoughts about c3 in work what could be done with it and be more beautiful than c++ ?
mavric
Well answered... are you familiar with the old game Zone 66? Any game that doesn't take control of the operating system isn't optimised enough in my book ;)
CurtainDog
MB: Is sending data to the GPU really language dependant? Isn't it going to take a lot of CPU anyway, regardless of the language? Not a rhetorical question, but an actual question :)Because if I look into the Draw methods of the GraphicsDevice class of XNA, it just calls C++ code, so there's some overhead of communicating with unmanaged code and a few sanity checks. But I doubt that's a real deal breaker.
JulianR
Oh come on. If your game is single threaded, then you simply can't utilize 100% of multicore CPU, because you only use one core. And making game multithreaded increases complexity dramatically because of synchronization issues (and yes, there are a lot of people with single core CPUs), so you should check core utilization (assuming that CPU affinity is set for game process). CPU bottleneck is no way language issue. C# is compiled into native code before execution so at least math operations runs on par with C++ (I tested it).
n0rd
The real difference between these two languages is resource management. In C++ it is explicit. In C# it tries to be implicit and THAT is a problem. When you run your game and get slowdowns in critical moment because garbage collector decided that it is a good time to do some cleanup, or if your process requires couple of gigs of memory (say only half of which is really used) because GC thinks it is not good time to deallocate memory and your game swaps extensively, then you do have a problem.
n0rd
@ n0rd: Having a single-threaded game simply isn't going to be an option in the future, which is my entire point. And the GC can be dealt with. Like pre-allocated object pools rather than newing up everything when you need it, to avoid creating garbage.
JulianR