4 ms·
I'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).
by pmjordan 17y ago
I'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...
- berntb 17y agoA Scheme compiling down to C for game development? That sounds incredibly fun! Gambit even looks mature. (I did some Common Lisp but have no experience with Scheme... wtf, no Scheme books on my mysafari?!) Damn you, pusher! I don't have time for hobbies! Uhm, I mean -- thanks for a really informative post. :-)
- huhtenberg 17y agoSame here, except that after using C and C++ for over a decade I find switching to another language quite trying. The habit of constantly thinking what machine code is generated from the higher language constructs is really hard to ignore. Moreover, I actually like C. But it is inconvenient. On the other hand C++ is convenient, but I don't like it. So I started playing with developing a dialect of C that adds support for parametrized code, closures, this pointer and type inference. All the stuff that I use or would like to use in C++, but in a syntactically cleaner way and without all the blubber that C++ accumulated through a design by committee. A hobby project, nothing too fancy :-)
- pmjordan 17y agoI had the problem of worrying about low-level nuts and bolts for a while too; I guess it must have been the jarring difference in expressiveness between C++ and Lisp that made me stop worrying in the end. I don't think you can realistically wean yourself from C++'s mind pollution gradually - you have to go cold turkey and go with a high level language, dynamic typing, garbage collection, not especially object oriented, etc. Do a couple of smaller projects with a language like that and you'll probably find that you don't really want that "better C++" of yours after all.
- huhtenberg 17y ago> you don't really want that "better C++" of yours after all I want it because it is an interesting project in itself. But I hear what you are saying.