Monday, August 11, 2008

C++ is dead?

I have a love/hate relationship with C++.

There, I said it.

C++ allows you to almost program to the metal, giving you extensions/intrinsics to code for the machine. It also allows you to use higher level constructs, like OOP and metaprogramming.

But to write a simple task, it is quite a pain. You have to create a project, compile, link, add the libraries, etc... To use any string operations, you have to use STL which is slow sometimes.

Sometimes I do like to write a quick & dirty script in Ruby to test something or for tools.

What does this have to do with the "C++ is dead" title? A post from C0DE517E.

While I agree C++ is not the best language in the world, it still is relevant. Just ask any games tech lead, or senior engineer who has spent days optimizing an inner loop for CPU performance. C++ is still the way to go for games, since games programming by definition pushes the hardware to its limit. The problem with other languages is that the compiler/language/interpreter hides the hardware for you (which is good in a lot of other problem domains), but games in the end is making the specific hardware work for you.

Yes, garbage collection is nice, but remember that consoles are embedded systems with limited resources. If you artists take up 85% of the available video ram in assets, you have to have control over the loading/unloading, not just hoping the garbage collector will get your hints and run when you tell it to.

I agree some things are *really* tedious to do in c++, and the syntax can be very not clear. But until somebody comes up with a language that is more powerful, allows you to program 'to the metal' and allows you to use better high-level constructs, while at the same time create optimized code that takes into consideration branch predictions, instruction pipelining and load-hit-stores, I think we're (to quote Larry David)"pretty, pretty, pretty pretty good!".


aaron said...

> You have to create a project, compile, link, add the libraries...

Not really. In VC:
c:\tmp>type test.cpp
#include <iostream>
using std::cout;
int main(){
cout << "hello world\n";

c:\tmp>cl /EHsc /Zi /nologo test.cpp

hello world


Likewise, with gcc (mingw)
c:\tmp>g++ test.cpp -o test.exe

hello world


As for libraries, you can add commonly used libraries to your build path. see the LIB environment variable for VC.

Btw, first time reader here -- hope i'm not out of line :)


R Caloca said...

Yes, you're right.. However on Ruby you could simply do:
> ruby
puts "hello world!"

and that's it!

sulfide said...

yes all that extra work in compiling c++ over using ruby..give me a break. I hate when people make big deals out of small things.