7 ms·
Ask HN: If C++ is so bad, what should game developers use?
I've been reading some of the C++ hate that's been on HN of late. I've been successfully convinced (not that it was hard) that C++ is a really terrible language. But, if that's the case, then what else are commercial game developers to use? Is pure C sufficient? What about Haskell, or is that too slow?
- jibiki 17y agoWhat kind of game are you writing? If you're just a hobbyist, you might want to try a popular choice like python. (Pygame is insanely well known.)
- olliesaunders 17y agoI edited the original post. I'm interested in commercial game projects. Real games, the kinds that you see in shops for PS and XBox etc.
- amichail 17y agoUse what most developers are using for the gaming platform of interest.
- olliesaunders 17y agoIsn't that C++? (I'm not very learned, here, I'm really asking about this for a friend).
- jibiki 17y agoAs far as I know, yes.
- trin_ 17y agowell pc-gaming/xbox is also getting more and more c#
- loup-vaillant 17y agoIt is C++. Note that this perfectly reasonable individual choice tend to ensnare us all in a local maximum. One route out of this local maximum could be CPUs optimized for garbage collection and a high rate of function call. I doubt we will see that any-time soon, though.
- loup-vaillant 17y agoMETA: Why the downmod? I assume it wasn't out of mere disagreement, so I must have made a specific mistake, but I can't see it (I answered the question, then stated an opinion which I think was on topic).
- smakz 17y agoIf you are interested in making games for consoles you are pretty much restricted to what the console maker's software development kit supports, which is usually C/C++. It's usually impractical to reverse engineer the hardware and supply your own system libraries in another language. Computer games are another story, but the same facts are generally true, that you should use the language which provides the libraries where most of the work is already done for you. There are the most number of game development kits for C++, so that's why C++ is popular for game development. For what it's worth, I have done a few games using the ORGE rendering engine and plugged the game elements (physics, AI) with separate libraries and it has worked fairly well. http://en.wikipedia.org/wiki/OGRE http://en.wikipedia.org/wiki/OGRE http://en.wikipedia.org/wiki/Havok_(software) http://en.wikipedia.org/wiki/Havok_(software) http://en.wikipedia.org/wiki/Box_2D http://en.wikipedia.org/wiki/Box_2D
- plinkplonk 17y ago"If you are interested in making games for consoles you are pretty much restricted to what the console maker's software development kit supports, which is usually C/C++. " Unless you want to write a lisp using that c/c++ sdk and then develop with the lisp you wrote. (http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp). So it certainly can be done. Whether you should is another matter. Post acquisition (by Sony) Naughty Dog seems to have shifted to c++ but seems to have shifted back partially to lisp (C++/ scheme combo as far as I can make out) for their "Uncharted" games for the PS3.(http://www.naughtydog.com/docs/Naughty-Dog-GDC08-Adventures-In-Data-Compilation.pdf http://www.naughtydog.com/docs/Naughty-Dog-GDC08-Adventures-... Warning PDF)
- Fargren 17y agoXNA is great, but your games will only be compatible with windows(and xBox). Haskell is definetely not a good idea.
- olliesaunders 17y agoWhy is Haskell a bad idea?
- Fargren 17y agoWell, 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 ammount of time, and you probably won't be able to do it at all. Haskell is great for math-oriented programs, but I wouldn't recommended for much else, in my opinion. http://hackage.haskell.org/ http://hackage.haskell.org/ is suppossed to be a good source for libraries, if you are intersted, but I can't get it to load.
- gburri 17y agoAnd what about Quake in Haskell : http://www.haskell.org/haskellwiki/Frag http://www.haskell.org/haskellwiki/Frag ?
- Fargren 17y agoFraq 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.
- caffeine 17y agoaddmitedly 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.
- ComputerGuru 17y agoDon'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.
- derefr 17y agoWhy 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?
- eli 17y ago"Newer" isn't necessarily better or more productive. Especially given the monumental task of having to write a game without the benefit of any of the libraries developed over the past few decades. Perhaps the reason there are no other viable options is because C++ is pretty well suited to the task?
- derefr 17y agoWhy would you have to lose the libraries? .so files are .so files; it doesn't matter what language they were written in, as long as they expose an API that can be cleanly wrapped by your own language.
- nicolas314 17y ago... and a standard ABI, otherwise you will never be able to link. C++ did not have standard name-mangling conventions until recently, which forced you to use the very same compiler to compile both your libraries and your own code. This is still unfortunately very much a concern with all these legacy systems out there. Your only solution is to expose your API as a C library or distribute your source code.
- thras 17y agoA lot of that "baroque, redundant complexity" comes from standards committee's refusal to make things easier on programmers at the cost of any smidgen of performance. And for certain tasks, like the highly competitive video game industry, uncompromising performance is exactly what the doctor ordered. You can always hire smarter programmers if you have to. On the other hand, it's hard to sell a game that runs or looks like crap at 60 fps.
- thras 17y agoI'm with you. Whatever you use, don't choose C++. Sure, everyone on your programming team knows C++ already. Yeah, your libraries are all written in it. And successful games have used it again and again. But if it's not one of the "cool" languages, you shouldn't be using it. Modern game developers should code in Ruby/Lisp. By the time you've finished coding all of your graphics libraries from scratch, Moore's law will have made computers fast enough to run them.
- derefr 17y agoWait, so why can't you use the C++ libraries from Ruby/Lisp?
- thras 17y agoI think that best thing to do is look at 1) the libraries you'll be using, 2) what your team is proficient at, 3) what's worked for other groups, 4) optimization potential. If you think that Ruby/Lisp is your answer to the above points, go for it. But I have the feeling that it won't be for many people.
- derefr 17y agoI 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 better idea to start in the low-level language? Because your team "knows it?" by that argument, all games would still be being developed in assembler, because the most senior members of the team would have more experience with that than any new-fangled language like C++.
- olliesaunders 17y agoLast time I heard, assembly wasn't considered out of bounds for high performance game programming by any means.
- nova 17y agoI think it's more that although C++ sucks there is no realistic alternative for this "niche".
- Dilpil 17y agoWhat other languages are out there that compile into machine code?
- olliesaunders 17y agoIf this is really that important then, according to the C++ FQA, you'd be much better off with C.
- anamax 17y ago> What other languages are out there that compile into machine code? It used to be that almost all languages compiled into machine code. And you, get off my lawn.
- JulianMorrison 17y agoC Objective-C D Pascal Haskell Ocaml ML Ada Fortran ... I could go on.
- ginkgo 17y agoThere is a very interesting talk by Tim Sweeney to this topic: http://lambda-the-ultimate.org/node/1277 http://lambda-the-ultimate.org/node/1277
- kazuya 17y agoHis 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.
- fpgeek 17y agoThey 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.
- miloshh 17y agoYou're right, C++ pretty much has no serious alternatives for games. And not just games, anything that involves computer graphics, physical simulation, computer vision or image processing. Python is excellent if some good soul has already written a library that does exactly what you need (in C or C++, obviously). The combination of numpy+PyOpenGL+PyCUDA is great for certain kinds of research projects (I have written a volume renderer in it) but probably far from commercial usability. Haskell has great potential, but the community is too small and too academic to produce the necessary libraries and tools (which is a lot of work with minimal scientific content). The key problem is the absence of an industrial-strength array facility - there are many kinds of arrays in Haskell, all somewhat clunky and incomplete. D might be a contender, but last time I looked the tools seemed very basic and it did not even support 64-bit systems.
- JabavuAdams 17y agoyay! Python + PyOpenCL + ... is on my shortlist for the next project. D is a dream to program in. The templates, especially, are so much nicer than C++ that I hate coding in C++ for a few days after doing D. OTOH, it's the same thing wrt runtime. Why spend a few days getting other people's crappy wrapper code working, FOR EACH LIBRARY, when you already know how to use, debug, and optimize those libraries for C/C++. It wastes a lot of time!
- zentux 17y agoI absolutely agree !! I hate C++ too, but as you said , there is no real alternative for it. Mixing C and python is a good idea ,but real world applications in my area (computer vision) use C++ widely ...
- timr 17y agoIf you let the language trolls on proggit and HN convince you that you must avoid C++ -- particularly whatever 'subset' of C++ scratches your itch with minimal complexity -- you've made a classic pointy haired boss mistake: letting the whims of the crowd make a technical decision for your project. Don't buy into the nonsense. C++ is a fine language. People have been using it for decades to do real work, and they probably still will be in another two decades, long after Ruby and Haskell and Blub have been discarded as 'archaic' by the next generation of 20-year-old language snobs.
- ygd_coder 17y agoContrary to popular belief. Java is actually pretty good.
- aceofspades19 17y agoI suppose if you like over-engineering
- ygd_coder 17y agoOver-engineering? You're confusing me with one of those guys that has to do a UML diagram before he can start coding.
- aceofspades19 17y agoI was mostly referring to the language. The standard library that comes with Java is over-engineered to the point of absurdity
- lincolnq 17y agoNot _quite_ to the point of absurdity. I kinda like it. Admittedly, I dislike it when I have to instantiate four classes to read the contents of a file. But I have also used the same flexibility to great advantage, and been burned in other languages when the standard library wasn't flexible enough.
- aceofspades19 17y agoWhat languages are these? because I have never used a language where the standard library was not flexible enough.
- artsrc 17y agoIf Java is good, then why isn't Scala better?
- wicknicks 17y agoC++ is definitely not a terrible language. It was one of the first OO programming mostly widely adopted (though today there are far better ways of doing OO with other programming languages). The problem with higher level languages is their performance. C++ sits somewhere between C and languages like Java, Python. I would say its probably a good place to program games which are both memory and CPU intensive.
- pmjordan 17y agoI've been contemplating this, too. C++ was my main language for a long time (~1999-2007) and about 30% of my consulting work is still in C++ (game development). I've found that while C++ code can be very clean and concise, it usually requires a lot of behind the scenes scaffolding, and it's very easy to get wrong even if you know the damn thing inside out. Programming in more expressive languages has certainly improved the quality of my C++ code, but there's only so much you can do. My use of other languages has therefore gradually increased - I currently use Clojure where I can, but I'm pretty flexible (PHP being the only language on my blacklist so far). For projects on which I'm a lone programmer, I'm free to use whatever language I want in theory; sometimes the customer has a preference, usually not, so the main restrictions are technical and legal: I'd like to use Clojure a lot more, but for game dev, it's problematic. Performance is the least of my worries, as I can drop to Java or even JNI for the rough bits. It's also a fantastic choice for server-side programming on multiplayer games. However, the JVM isn't allowed on the iPhone, say, and unrealistic or disallowed on consoles. (the Nintendo DS has 4MB of RAM, for example; licensing/porting is an issue) For pure PC/Mac game dev it's probably fine, although if by any chance you want to port later, good luck. There was a submission on HN a few months back about using Gambit Scheme for iPhone and Mac programming. Googling easily retrieves some useful information on this, but the general idea is that it compiles to C, and you can actually write Scheme functions with inline C/C++/Objective-C code, so you're using a 2-stage compilation process and retain full control while using a very expressive high-level language. I'm going to try this with my next iPhone game, as I'm not all that impressed with Objective-C so far. It looks extremely promising. There are of course other languages which have compilers that generate C; I believe there are some Common Lisp implementations, although especially for game dev I'm not sure if there's any advantage in using CL over Scheme. If using a full-blown Lisp feels too high level, there are some Lispy efforts that are essentially very fancy C preprocessors, e.g. BitC[1] or SC[2]. The latter is literally C with an S-Expression syntax; I'd be interested how compactly all of C++'s features could be expressed in such a language. Not that you'd want the arcane contortions of C++ templates when you have real macros. Moving away from C a bit more, there are of course Forth and other languages in a similar vein. As I've mentioned, I'll be going down the Gambit Scheme route in future projects, as it has a very nice interface to C/C++ (this is critical when dealing with game development oriented libraries - I'd probably make this the top priority in choosing a language for this purpose), it's very stable and mature, and it's a Lisp. I'll try and write a postmortem of some sort when the time comes. My main worry is the behaviour of GC in an environment with hard memory limits (no virtual memory or paging), but if the allocator and GC are well written it should be less risky than explicit memory management. [1] http://www.bitc-lang.org/ http://www.bitc-lang.org/ [2] http://super.para.media.kyoto-u.ac.jp/~tasuku/sc/index-e.html http://super.para.media.kyoto-u.ac.jp/~tasuku/sc/index-e.htm...
- s-phi-nl 17y agoI am under the impression that Lua is widely used for video games.
- Meatshoes 17y agoLua is often used as an embedded scripting language within level editors, for example to keep track of the progress made on a quest or to trigger an event when the character reaches a certain point. Lua isn't used to code the game engine itself (in the vast majority of cases, there may be some obscure examples of game engines written in Lua)
- silentbicycle 17y agoRight - The stuff that needs high performance or low-level access (e.g. graphics code) is written in C or C++, but most of the "soft layer" is scripted in Lua. See: http://www.c2.com/cgi/wiki?AlternateHardAndSoftLayers http://www.c2.com/cgi/wiki?AlternateHardAndSoftLayers
- whye 17y agoMuch of World of Warcraft's user interface is written in Lua, and I'm not sure I'd classify WoW as an obscure example.
- xsmasher 17y agoBut the game engine is not. It doesn't use LUA to push polygons.
- whye 17y agoThat is correct, but the game does use it for a lot more than just scripting. ps: Lua, not LUA -- it's the Portuguese word for moon, not an acronym :)
- Scriptor 17y agoSo we can conclude then that games have many different facets to them and they can be loosely coupled enough that you can implement them using different technologies. The interface could be done in Lua, since it doesn't require intense computations when compared to graphics and physics engines.
- Maro 17y ago"C++ sucks" because it is widely used, its socio-techical landscape is well explored, including the "sucks" segment. In other words, most other languages suck as much as C++, they're just not that widely used, or have not been around as much. If you're writing your own game project you can use a sane, minimalistic and syntactically pleasing subset of C++ and gain all the pedal-to-the-metal advantages. Don't discard C++ because other people say it is terrible. Other people are usually wrong. Make up your own mind. For example, the Keyspace code is organized into classes; we use inheritance and polymorphism; we use templates in a few select cases; but we completely avoid exceptions, operator overloading (actually operators) and the STL altogether (we implement our own containers). It doesn't matter what others think about this specific subset - it works for us, we work well in this formalism, make few mistakes and produce good code that runs fast.
- dkarl 17y agoVery good points. Since C++ is a good match for the way people are taught to think about programming, it's obvious that anything good programmers can't easily and consistently get right is the fault of the language. With Haskell, you can't rule out unfamiliarity as the cause of any difficulties until you're already heavily invested in it. Most people really have no basis for challenging the statement that Haskell is perfectly suited for game programming in the hands of a competent programmer. Pragmatically, for the OP, I think it's safe to say that C++ and Haskell are both very challenging languages that take a long time to master. The advantage of C++ is that there's ample evidence of its suitability for various domains. The advantage of Haskell is that you'll learn a different way of programming. The decisive factor may be whether it's your own money on the line.
- danek 17y agowhat about D or OCaml? OCaml can compile to machine code and supposedly can acheive c++ level performance. D is allegedly a "fixed" c++. i haven't used either, just conjecturing based on what i've heard through the grapevine.
- bonecandy 17y agoWait a couple of years and you can use MacRuby ;D
- zandorg 17y agoI'd code the graphics code in C++, and the logic/game/AI code in Lisp.
- mrshoe 17y agoC++ 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).
- nickpp 17y agoI see that you would, but have you? Or did anybody?
- mrshoe 17y agoI have worked on major console games and written games in both C and C++. I also maintain an open source raytracer which I've implemented in C, C++, D, and python. So yes, I speak from experience. Eve online is a great example of a game for which almost all game logic is in python (stackless). The "engine" is in C++, I think (not sure on that one). So I would adopt their model but use C instead of C++.
- bd 17y agoAlso Civilization 4 used Python extensively: http://www.python.org/about/quotes/ http://www.python.org/about/quotes/ (look for "Firaxis Games")
- omouse 17y agoI saw a game that used Python (I think, maybe it was Ruby) and then dropped down to C for the high-performance bits and it was still slow as shit because of the Python code.
- jomohke 17y agoThe D programming language [http://www.digitalmars.com/d/ 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++.
- iamwil 17y agoDepends on what kind of games you want to make. If you're looking for 2D platforms, try Actionscript or Lua Love. http://love2d.org/ http://love2d.org/
- JulianMorrison 17y agoI'm not sure how ready it is now, but Haskell's nested data parallelism might be worth looking into as a forward strategy for things like physics and in-CPU graphics engines, since it should make very effective use of many-core processors and is expected to later (transparently) gain the ability to distribute work onto the GPU. This is if you want to do something more fancy than OpenGL, such as ray-trace or use splines. Haskell's extreme facility with small light threads and its implicit parallel "strategies" could also make updating a rule based game board an almost mathematical, rather than detail-grovelling exercise. You will not be able to get monkeys to program in Haskell. Whether this is a problem depends on your plans.
- gord 17y agoany mix of : C, python, lua, scheme
- chipsy 17y agoI would take a data-oriented view. Most of the performance of a game stems from finding a sweet spot combination of data structures and data relationships so that data is processed at real-time rates, is accessible everywhere, and can be immediately applicable to the algorithms you plan to use. If you design relationships-first, the way you would design a database, you can figure out a data layout that doesn't involve any high-level semantics to speak of, just classic data structures from CS: lists, arrays, graphs and trees to order things, records and hashes to name them. Go through each type of value and cross-index it across all the structures it needs to be accessed by. Then write intersectable queries into the structures to express a complex gameplay question like "Find all the enemy actors that are near mission objective X" as the composable "Find positions between boundaries A,B,C,D, that belong to actors of the enemy type, where A,B,C,D are some distance relative to the position of the objective entity with the name of X." Since you aren't writing a generic all-purpose database, this isn't a hard problem. It's just time-consuming to nail down the data model that captures all of it. I think you will agree that a fancy language isn't necessary to implement such an approach to game programming. Done that way, data mostly ends up being pointers. If your game is processing-light(which with today's desktop hardware primarily means avoiding 3d computation), you don't need a fast language: I'm most familiar with doing game code for Python and Flash and they can do just fine on modestly-sized datasets too.
- csmeder 17y agoPersonally, I would like to see a commercial game developer use FORTH. from: http://www.economicexpert.com/a/Forth:programming:language.htm http://www.economicexpert.com/a/Forth:programming:language.h... "Forth became very popular in the 1980s because it was well suited to the small microcomputers of that time: very efficient in its use of memory and easily implemented on a new machine. At least one home computer, the British Jupiter ACE, had Forth in its ROM-resident OS. The language is still used in many small computerized devices (called embedded systems) today for three main reasons: efficient memory use, shortened development time, and fast execution speed. Forth is also infamous as being one of the first and simplest extensible languages. That is, programmers can easily extend the language with new commands appropriate to the primary programming problem in the particular application area. Unfortunately, extensibility also helps poor programmers to write incomprehensible code. The language never achieved wide commercial use, perhaps because it acquired a reputation as a "write-only" language after several companies had product failures caused when a crucial programmer left. In addition, the ease of implementing Forth on a given processor meant that the barrier to self-development of a Forth system was quite low, so that commercial suppliers were, in effect, competing head-to-head with hobbyists, many of whom supported the idea that software should be free."
- Zarathu 17y agoC
- InclinedPlane 17y agoC++ isn't bad, per se. It's an incredibly powerful and rich language, verging on being a meta-language that allows you to create your own language. However, that flexibility is a double edged sword. Just like Perl or Javascript, any powerful, flexible language can, and will, be abused. The main downfall of C++ is probably that it's too flexible in every direction. It takes an equivalent amount of effort to do the "right" thing as to do the "wrong" thing. In a sense, the language makes no value judgments regarding design. Which is helpful in some ways because it doesn't lock you into the straight-jacket that Java does, for example, but it doesn't encourage users to fall into a "pit of success" either (which a truly good language should, even if it is ultimately flexible enough to let you do those "wrong" things).
- mark_l_watson 17y agoI used C++ when I worked on game AI and a few Nintendo U64 games, also for some virtual reality stuff for Disney and SAIC. Right choice for the games, in retrospect probably not for VR. C++ is fine when you need high performance and can live with more expensive development.