views:

611

answers:

7

This is an attempt to rephrase a question I asked earlier. I'd like to know why C++ seems to be the language of choice for certain thick client apps. The easiest example I can think of is video games and my favorite app VirtualBox.

Please don't close this post I'm just trying to understand why this is the case.

+3  A: 

It's easier to make the app cross platform with c++ than with .net (huge advantage in my point of view as you can aim the game to mac users also for example)

fmsf
virtualBox is cross-platform (Mac, Linux, Windows, Solaris) so I'm sure this was part of their motivation, as well as performance needs.
Jay
Oki, didn't knew that :)
fmsf
+8  A: 

There are lots of potential reasons:

  • Speed increases either perceived or real.
  • Previous knowledge. There are a lot of people out there that have been programming C++ for 20+ years. Not so with C#.
  • Existing code. It is true that .Net has a lot of capability wrapped up in the framework. Even then it still doesn't compare to the decades of libraries that exist for C++.
  • Cross platform development. C++ is much easier to port.
  • Determinism. I will shamelessly steal from ctacke's answer. He sums it up best, but being able to determine exactly what happens when at a very low level can be very necessary for programming something like a game that is time critical.
EBGreen
Real speed gains, since we're talking about lowlevel code, not glue or game code, both which have been moving to scripting lately. You simply can't do vector and matrix math at the same speed with as little memory in C#. stuff like high level AI though, that's Lua nowadayws.10 times slower than C#
Robert Gould
I agree that for game programming the speed gains are real. I was just trying to give a more general answer.
EBGreen
+2  A: 

Primary reasons might be:

  1. Performance
  2. Higher level of control over low level things
  3. An existing code base
Mehrdad Afshari
+3  A: 

For a large set of applications it comes down to speed and determinism.

Native code simply runs faster because you have a compiler that can take it's time to do the best possible job at creating machine language. The only person that has to wait is the developer. Managed code has to go from IL to machine language while running. Getting it done quickly is more important than getting it in the best possible form, because the user has to wait while it's happening. Better speed == better user experience.

Determinism is key in many things (like games) because you'd like to know, exactly, when things that take time are going to happen. When I make a memory allocation or deallocation, it takes time. I'd like that to happen when we're loading up a new game level and no one will notice, not while the user is strafing left getting his ass shot off by his friend in an ultimate death match. A stutter there ends up with cussing and a game controller on the other side of the room. With native code, you explicitly control when these things happen. With managed code, the GC decides when that happens, and there's no way to exactly know when or how long that may be.

ctacke
+24  A: 

As a profesional game dev working on AAA titles I can tell you. Reason number 1 is C++ and C will compile and run on any platform say a PS3 or an NDS. Next platform makers only provide robust C libraries to interface with hardware. The reason behind this is C and C++ are free, and not owned by one corporation, and because they were designed for close to the metal low level programming. This means game devs need to know C/C++ which forms a feedback loop. However many devs nowadays make their toolsets in C# or Java, but that's because performance isn't critical.

Now this posture might seem fanatic to most web developers, but games need to process entire slices of complex simulations and rendering upto 60 times per second, few web apps are bound to stay within that latency rate, so the needs are different.And same reason few web services are produced with C++.

However high level AI, and gameplay( the rules ) are scripted because of the development speed increase and ability to fine tune the game. Also because this amounts to about roughly 15% of the resources, so we can splurge here, and let the designers do their job. Also note that coding a fexible rule system would take about the same resources anyways even if done in C++. Oh and not all platforms allow Jit code which would be nice :)

And of course as mentioned memory control, if you use even 1 byte more memory than provided by the hardware, it doesn't slow down like a PC. It crashes. So we love our naked pointers, custom allocators and RAII.

Robert Gould
+1  A: 

In the cases you are mentioning, the main reasons are easier access to low-level system API, speed and portability.

Nemanja Trifunovic
A: 

Seems to me like this is good summary of the answer:

  1. More granular control of how the code is executed
  2. Portability
  3. Knowledge and experience with the language
  4. Running code closer to bare-metal
  5. Efficiency
  6. Runs on anything
  7. language is not owned by any particular organization
Agile Noob