Live data from Hacker News

Ask HN: If C++ is so bad, what should game developers use?

news.ycombinator.com

61–70 of 127 posts

Re: Ask HN: If C++ is so bad, what should game developers use?

#61
post #55
post #35

Earlier quoted context omitted.

That advice never works. The problem is data structures . If your high-level prototype uses complex data structures of e.g. Python, you will not be able to access them from C++. You will need to rewrite the whole thing anyway. The only way you might get away with this approach is if your application is essentially a number of separate scripts that communicate through files. Then you can rewrite the key scripts in C++…

Part of Civ IV (mostly gui stuff) is in python. They seem to be able to communicate with the C++ core fine.

But I assume they did not write the game in Python and the optimize parts in C++. Quite the opposite - they wrote it in C++ and then found that some part (e.g. GUI) is growing in complexity while not being crucial for performance, at which point it is a good decision to use a scripting language for it.

That is a pretty common approach, but what was suggested above (writing first in HLL and then rewriting parts in C++) is, to my knowledge, never done in practice.

Re: Ask HN: If C++ is so bad, what should game developers use?

#62
post #60

C++ violates the Zen of Python's axiom that "explicit is better than implicit" all over the place. C does not; it is very explicit. I would write as much as possible in Python and use C for the performance critical stuff (which, for a game, is a large portion).

I see that you would, but have you? Or did anybody?

Re: Ask HN: If C++ is so bad, what should game developers use?

#63
The D programming language [http://www.digitalmars.com/d/] was designed primarily to be a better C++. It has C-style syntax, a vaguely similar OO model to Java, and compiles directly to machine code, with performance as priority (it even allows you to drop to assembly if desired). The lack of C backwards compatibility allowed them to clean up a lot of the uglier areas of C++.

Re: Ask HN: If C++ is so bad, what should game developers use?

#65
post #20
post #14

Earlier quoted context omitted.

Well, for once, it's not particulary fast, but that's not a concern for all games(it's not slow either, but it's quite hard to optimize). The real deal is that it's a completely functional language with not much support, as far as games go. You won't find any graphics libraries, so you'll have to make them from scratch. Unless you have been programing in funcitonal languages for a long time, this will take an absurd…

Fraq was made in 2005 and it looks worse than quake 3, wich was made 6 years early (addmitedly by a big studio instead of jut one person, but the point still stands). It is possible to make games in Haskell, but it's closer to a theorical exercise than it is to an aproach to proffesional game-making.

addmitedly by a big studio instead of jut one person, but the point still stands

The point doesn't really stand, no. A big studio making a game over a long time period will obviously do a much better job than an undergraduate writing his thesis (yes, Frag was an undergrad thesis project).

To be fair, I think there are legitimate difficulties making games in Haskell, primarily related to the predictability of performance. GHC is a complicated and rather ingenious compiler incorporating many optimizations. While this is useful, it also means that performance (especially the responsiveness of the GC) can be unpredictable. Predictability of performance is quite important for games. In fact, this could be a good reason to try writing games in Ocaml.

The more probable reason is simply that the set of people working on big-budget games with the expertise to do in Haskell what they've learned to do in C++ is small.

Re: Ask HN: If C++ is so bad, what should game developers use?

#66
post #25

Earlier quoted context omitted.

I didn't say I wanted to use Ruby or Lisp--I was simply denying the parent's point that one would have to "write the graphics libraries from scratch." Besides, isn't the advice for optimizing every other kind of project: 1. Start in a high-level language 2. Port any bits that profile as slow to a low-level language, and then interface them into your HLL code Why, all of the sudden, when you're coding a game, is it a…

Last time I heard, assembly wasn't considered out of bounds for high performance game programming by any means.

Last you heard must have been a while ago. Even the engines aren't being written in assembly. Writing in x86 yields slower and less optimized code than letting gcc -o3 etc compile your C code in x86. It simply gets too complex to manage in assembly.

Re: Ask HN: If C++ is so bad, what should game developers use?

#67
post #10

Don't let them scare you away... C++ is fine if you use what you need and take the time to actually understand the tools you're using.

Why is C++ suddenly "fine" when you have no other options? There could easily be a language with all the close-to-the-metal advantages and none of the baroque, redundant complexity of C++; why must we be content to use the same language as everyone else in the industry, rather that scratching this itch and building a newer, more productive one?

> Why is C++ suddenly "fine" when you have no other options? There could easily be a language with all the close-to-the-metal advantages and none of the baroque, redundant complexity of C++

There is such a language, it is called C.

Re: Ask HN: If C++ is so bad, what should game developers use?

#68
post #14

Earlier quoted context omitted.

Why is Haskell a bad idea?

Well, for once, it's not particulary fast, but that's not a concern for all games(it's not slow either, but it's quite hard to optimize). The real deal is that it's a completely functional language with not much support, as far as games go. You won't find any graphics libraries, so you'll have to make them from scratch. Unless you have been programing in funcitonal languages for a long time, this will take an absurd…

As a professional Haskell programmer, I wouldn't say Haskell is harder to optimize than C++, I'd say it is different to optimize. Good Haskell programmers start with thinking about high-level concepts and algorithms right, rather than starting with (relatively) low-level, performance-focused good. And when they optimize, the things they're optimizing for are different: space leaks, excessive (and too little) laziness, appropriate data structure sharing (which can be tricky when using laziness to recursively compute a data structure) and so on.

After that, if necessary, they can look at lower-level details (escaping to a high-performance library in another language, skipping things like array bounds check, other low-level tricks, etc.). However, one of the powerful advantages of Haskell is that this sort of low-level, error-prone, ugly code can be isolated behind clean, predictable, functional interfaces. A great example of this is Haskell's ByteString library, where the low-level details are complex enough that I don't necessarily understand all of them, but the external interface is one even a beginning Haskell programmer can effectively and efficiently use.

Re: Ask HN: If C++ is so bad, what should game developers use?

#69
post #56
post #23

There is a very interesting talk by Tim Sweeney to this topic: http://lambda-the-ultimate.org/node/1277

His point about fp appears to get no traction in video game developers around me. I heard some iPhone app developers are trying to use Haskell to create games, though.

They are. Ryan Trinkle (one of the developers behind this) gave a talk about why they are using Haskell (echoing Tim Sweeney's talk, but adding his own perspective) at a meeting of BostonHaskell. Among other things, they've made a custom iPhone cross-compiler port of GHC that is quite impressive (in the waltzing bear sense)

Since their basic approach is applicable to other platforms, it will be interesting to see if GHC ends up with clean, extensible support for mobile cross-compilation in the future.

Re: Ask HN: If C++ is so bad, what should game developers use?

#70

I am under the impression that Lua is widely used for video games.

Lua is pretty popular because it is a simple scripting language that you can either run in an interpreter, or compile to C. The interpreter is easily embeddable, and you can call C functions from it. All of this makes for pretty rapid development without sacrificing speed for the things that it is suitable for.
Post reply on HN