<p>C++ just sucks too much of my time by making me micro-manage my own memory, making me type far too much (hello <code>std::vector&lt;Thingy&gt;::const_iterator it = lotsOfThingys.begin()</code>), and boring me with long compile times.  What's the single best alternative for serious real-time graphics programming?  Garbage collection is a must (as is the ability to avoid its use when necessary), and speed must be competitive with C++.  A reasonable story for accessing C libs is also a must.</p>

<p>(Full disclosure: I have my own answer to this, but I'm interested to see what others have found to be good alternatives to C++ for real-time graphics work.)</p>

<p><strong>Edit:</strong> Thanks everyone for the thoughtful replies.  Given that there's really no "right" answer to this question I won't be selecting any particular answer.  Besides I'd just pick the language I happen to like as a C++ alternative, which wouldn't really be fair.</p>

[{'answer_id': 72959, 'author': 'Drealmer', 'author_id': 12291, 'author_profile': 'https://Stackoverflow.com/users/12291', 'pm_score': 4, 'selected': False, 'text': '<p>C# is a nice language that fits your requirements, and it is definitely suited for graphics, thanks to the efforts of Microsoft to provide it with great tools and libraries like Visual Studio and XNA.</p>\n'}, {'answer_id': 72986, 'author': 'scable', 'author_id': 8942, 'author_profile': 'https://Stackoverflow.com/users/8942', 'pm_score': 4, 'selected': False, 'text': '<p>What about <a href="http://www.digitalmars.com/d/2.0/comparison.html" rel="noreferrer">D Programming Language</a>?</p>\n\n<p>Some links requested in the comment:</p>\n\n<p><a href="http://www.digitalmars.com/d/2.0/windows.html" rel="noreferrer">Win32 Api</a></p>\n\n<p><a href="http://www.dsource.org/projects/derelict/" rel="noreferrer">Derelict (Multimedia lib)</a></p>\n'}, {'answer_id': 73244, 'author': 'yrp', 'author_id': 7228, 'author_profile': 'https://Stackoverflow.com/users/7228', 'pm_score': 2, 'selected': False, 'text': '<p>There are no true alternatives for big AAA titles, especially on the consoles. For smaller titles C# should do.</p>\n'}, {'answer_id': 73247, 'author': 'Pieter', 'author_id': 5822, 'author_profile': 'https://Stackoverflow.com/users/5822', 'pm_score': 4, 'selected': False, 'text': "<p>Real-time + garbage collection don't match very well I'm afraid.</p>\n\n<p>It's a bit hard to make any real-time response guarantees if a garbage collector can kick in at any time and spend an undefined amount of processing...</p>\n"}, {'answer_id': 73430, 'author': 'James Hopkin', 'author_id': 11828, 'author_profile': 'https://Stackoverflow.com/users/11828', 'pm_score': 4, 'selected': False, 'text': '<p>Perhaps a hybrid approach. Python and C++ make a good combination (see, for example, PyGame).</p>\n'}, {'answer_id': 73642, 'author': 'Adi', 'author_id': 9090, 'author_profile': 'https://Stackoverflow.com/users/9090', 'pm_score': 2, 'selected': False, 'text': "<p>C# is a good answer here - it has a fair garbage collection (although you'd have to profile it quite a bit - to change the way you handle things now that the entire memory handling is out of your hands), it is simple to use, have a lot of examples and is well documented.\nIn the 3D department it gives full support for shaders and effects and so - that would be my choice.</p>\n\n<p>Still, C# is not as efficient as C++ and is slower due to overhead, so if it is speed and the flexibility to use any trick in the book you like (with pointers and assembly if you like to get your hands dirty) - stick to C++ and the price would be writing way more code as you mentioned, but having full control over everything including memory management.</p>\n"}, {'answer_id': 73704, 'author': 'Johan Moreau', 'author_id': 12033, 'author_profile': 'https://Stackoverflow.com/users/12033', 'pm_score': 2, 'selected': False, 'text': "<p>Like James (hopkin), for me, the hybrid approach is the best solution. Python and C++ is a good choice, but other style like C#/C++ works. All depends of your graphical context. For game, XNA is a good platform (limited to win32), in this case C#/C++ is the best solution. For scientific visualization, Python/C++ is accepted (like vtk's bindings in python). For mobile game JAVA/C++ can works...</p>\n"}, {'answer_id': 73935, 'author': 'DevilDog', 'author_id': 323425, 'author_profile': 'https://Stackoverflow.com/users/323425', 'pm_score': 3, 'selected': False, 'text': '<p>Sometimes, looking outside the beaten path you can find a real gem.  You might want to consider <a href="http://www.purebasic.com" rel="nofollow noreferrer">PureBasic</a> (Don\'t let the name mislead you).  Here\'s some details:</p>\n\n<p>PureBasic Features </p>\n\n<ul>\n<li>Machine Code (Assembly) executables (FASM)\n\n<ul>\n<li>In-line Assembly support </li>\n<li>No run-times needed (no DLLs needed,etc.) 1 executable file  </li>\n<li>Tiny executables (as small or smaller/as fast or faster than C++ w/out the runtime)  </li>\n<li>You can write DLLs  </li>\n<li>Multi-thread support </li>\n<li>Full OS API support  </li>\n</ul></li>\n<li>Multi-platform support \n\n<ul>\n<li>Windows 95-2003</li>\n<li>Linux</li>\n<li>Mac-OS X</li>\n<li>Amiga  </li>\n</ul></li>\n<li>2D &amp; 3D game development  \n\n<ul>\n<li>DirectX  </li>\n<li>OGRE  </li>\n</ul></li>\n<li>Generous Licensing  \n\n<ul>\n<li>Inexpensive (79 Euros or about $112) </li>\n<li>Life-time license (all future updates &amp; versions included)  </li>\n<li>One price for all platforms  </li>\n</ul></li>\n<li>External Library support  \n\n<ul>\n<li>3rd party DLLs </li>\n<li>User Libraries  </li>\n</ul></li>\n<li>On-line Support \n\n<ul>\n<li>Responsive development team led by it\'s creator</li>\n<li><a href="http://www.purebasic.fr/english/index.php" rel="nofollow noreferrer">On-line forum</a>\n\n<ul>\n<li>One place for answers (don’t have to go all over the net)  </li>\n<li>Huge amount of sample code (try code out while in IE with IEtool)  </li>\n<li>Fast replies to questions </li>\n</ul></li>\n</ul></li>\n<li>Bonus learning (alternative to learning C++)  \n\n<ul>\n<li>API  </li>\n<li>Structures </li>\n<li>Interfaces  </li>\n<li>Pointers</li>\n</ul></li>\n</ul>\n\n<p>Visit the online forum to get a better idea of PureBasic (<a href="http://www.purebasic.fr/english/index.php" rel="nofollow noreferrer">http://www.purebasic.fr/english/index.php</a>) or the main site: <a href="http://www.purebasic.com" rel="nofollow noreferrer">www.purebasic.com</a></p>\n'}, {'answer_id': 74401, 'author': 'R Caloca', 'author_id': 13004, 'author_profile': 'https://Stackoverflow.com/users/13004', 'pm_score': 0, 'selected': False, 'text': "<p>If your target is a PC, I think you can try C#, or embed <strong>Lua</strong> in your C++ app and run scripts for 'high-level' stuff. However if your target is a console, you <strong>must</strong> manage your own memory!</p>\n"}, {'answer_id': 74566, 'author': 'Nathan', 'author_id': 3623, 'author_profile': 'https://Stackoverflow.com/users/3623', 'pm_score': 4, 'selected': False, 'text': '<p>Some variation of Lisp that compiles to machine code could be almost as fast as C++ for this kind of programming. The <a href="http://www.naughtydog.com/" rel="noreferrer">Naughty Dog</a> team created a version of Lisp called <a href="http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp" rel="noreferrer">Game Oriented Assembly Lisp</a>, which they used to create several AAA titles, including the Jak and Daxter series. The two major impediments to a Lisp approach in the game industry would be the entrenched nature of C/C++ development (both tools and human assets are heavily invested in C/C++), as well as the difficulty of finding talented engineers who are stars in both the game programming domain and the Lisp language.</p>\n\n<p>Many programming teams in the industry are shifting to a hybrid approach wherein the real-time code, especially graphics and physics code, is written in C or C++, but game logic is done in a higher-level scripting language, which is accessible to and editable by programmers and non-programmers alike. <a href="http://www.lua.org/" rel="noreferrer">Lua</a> and <a href="http://www.python.org/" rel="noreferrer">Python</a> are both popular for higher-level scripting.</p>\n'}, {'answer_id': 74745, 'author': 'Nemanja Trifunovic', 'author_id': 8899, 'author_profile': 'https://Stackoverflow.com/users/8899', 'pm_score': 0, 'selected': False, 'text': '<p>Objective-C looks like a good match for your requirements (the latest version with optional GC), although it is too dynamic and Smalltalk-like for my taste.</p>\n'}, {'answer_id': 74750, 'author': 'Game_Overture', 'author_id': 13115, 'author_profile': 'https://Stackoverflow.com/users/13115', 'pm_score': 0, 'selected': False, 'text': '<p>XNA is your best bet I think. Being supported by the .NET framework you can build for a Windows or Xbox 360 platform by simply changing a setting in Game Studio. Best yet, all the tools are free!</p>\n\n<p>If you decide to go with XNA you can easily get started using their quickstart guide\n<a href="http://creators.xna.com/en-US/quickstart_main" rel="nofollow noreferrer">XNA Quickstart guide</a></p>\n\n<p>It has been a rewarding and fun experiance for me so far, and a nice break from the memory management of C++.</p>\n'}, {'answer_id': 75555, 'author': 'Dima', 'author_id': 13313, 'author_profile': 'https://Stackoverflow.com/users/13313', 'pm_score': 4, 'selected': False, 'text': '<p>I disagree with your premise.  When used carefully and properly, C++ is a great language, especially for a domain like real-time graphics, where speed is of the essence.</p>\n\n<p>Memory management becomes easy if you design your system well, and use stl containers and smart pointers.</p>\n\n<p><code>std::vector::const_iterator it = lotsOfThingys.begin())</code> will become much shorter if you use</p>\n\n<p><code>\nusing namespace std;<br>\ntypedef vector::const_iterator ThingyConstIter;\n</code></p>\n\n<p>And you can shorten compile times significantly by breaking up your systems into reasonably self-contained modules, by using precompiled headers, or by using the PIMPL idiom.</p>\n'}, {'answer_id': 75756, 'author': 'Markowitch', 'author_id': 11964, 'author_profile': 'https://Stackoverflow.com/users/11964', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n  <p>Garbage collection is a must (as is\n  the ability to avoid its use when\n  necessary)</p>\n</blockquote>\n\n<p>You can't disable a garbage collector temporarily. You would need a deterministic garbage collector then. But such a beast does come with a performance hit also. I think BEA JRockit is such a beast and then you should stick to Java.</p>\n\n<p>Just to comment on your example; typedef is your friend...</p>\n\n<pre><code>typedef std::vector&lt;Thingy&gt; Thingys;\nThingys::const_iterator it = lotsOfThingys.begin()\n</code></pre>\n"}, {'answer_id': 75804, 'author': 'komma8.komma1', 'author_id': 13355, 'author_profile': 'https://Stackoverflow.com/users/13355', 'pm_score': 2, 'selected': False, 'text': "<p>I would say the D programming language is a good option. You can link to C object files and interface with C++ code through C libraries. D has garbage collection, inline assembly, and game developers have created bindings to SDL and OpenGL libraries, and are also actively working on new game development apis. I love D. Too bad my job doesn't demand it's use. :(</p>\n"}, {'answer_id': 75838, 'author': 'Martin Cote', 'author_id': 9936, 'author_profile': 'https://Stackoverflow.com/users/9936', 'pm_score': 4, 'selected': False, 'text': "<p>I wouldn't discard C++.  In fact, I would consider adding Boost to your C++ library, which makes the language much more usable.  Your example would become:</p>\n\n<pre><code>BOOST_FOREACH( Thingy&amp; t, lostOfThingys ) {\n    // do something with 't'\n}\n</code></pre>\n\n<p>Boost has tons of tools that help make C++ a better language.</p>\n"}, {'answer_id': 76040, 'author': 'mittens', 'author_id': 10188, 'author_profile': 'https://Stackoverflow.com/users/10188', 'pm_score': 3, 'selected': False, 'text': '<p>I completely agree with the mention of C# for graphics programming. It has the slight disadvantage of being a managed language and allowing the garbage collector free reign over your application is framerate suicide after a while but with some relatively intelligent pool allocations made early in the program\'s life any real issues can be avoided.</p>\n\n<p>Several people have already mentioned XNA, which is incredibly friendly and well-documented and I would like to echo that recommendation as well. I\'m personally using it for my hobby game projects and it has treated me very well.</p>\n\n<p>XNA isn\'t the only alternative, though. There is also SlimDX which is under constant development as a means of providing a lean wrapper of DirectX in a similar fashion as Managed DirectX (which was, I believe, discontinued by Microsoft in favor of XNA). Both are worthy of research: <a href="http://code.google.com/p/slimdx/" rel="nofollow noreferrer">http://code.google.com/p/slimdx/</a></p>\n'}, {'answer_id': 76156, 'author': 'McKenzieG1', 'author_id': 3776, 'author_profile': 'https://Stackoverflow.com/users/3776', 'pm_score': 2, 'selected': False, 'text': '<p>If you are targeting Windows, C++/CLI (Microsoft\'s .NET \'managed\' dialect of C++) is an interesting possibility, particularly if you want to leverage your C++ experience. You can mix native code (e.g. calls to C-style libraries) with .NET managed code quite seamlessly, and take advantage of .NET GC and libraries.</p>\n\n<p>As far as concerns about GC impacting \'real time\' performance, I think those tend to be overblown. The multi-generational .NET GC is very good at never taking much time to do a collection, unless you are in some kind of critical low-memory situation. I write .NET code that interacts with electronic derivatives exchanges, where time delays == lots of $$$, and we have never had a GC-related issue. A few milliseconds is a long, long time for the GC, but not for a human interacting with a piece of software, even a \'real time\' game. If you really need true "real time" performance (for medical devices, process control, etc.) then you can\'t use Windows anyway - it\'s just not a real-time OS.</p>\n'}, {'answer_id': 81496, 'author': 'MSalters', 'author_id': 15416, 'author_profile': 'https://Stackoverflow.com/users/15416', 'pm_score': 4, 'selected': False, 'text': "<p>Let's not forget to mention the new 'auto' use:</p>\n\n<pre><code>auto it = lotsOfThingys.begin(); // Let the compiler figure it out.\nauto it2 = lotsOfFoos.begin();\nif (it==it2) // It's still strongly typed; a Thingy iter is not a Foo iter.\n</code></pre>\n"}, {'answer_id': 125586, 'author': 'PhiLho', 'author_id': 15459, 'author_profile': 'https://Stackoverflow.com/users/15459', 'pm_score': 2, 'selected': False, 'text': '<p>Lot of game engines can fit your need, I suppose. For example, using SDL or Cairo, if portability is needed. Lot of scripting languages (coming in general with easy syntax and garbage collection) have binding to these canvas.<br>\nFlash might be another alternative.</p>\n\n<p>I will just point out <a href="http://processing.org/" rel="nofollow noreferrer" title="Processing">Processing</a>, which is <em>an open source programming language and environment for people who want to program images, animation, and interactions.</em></p>\n\n<p>Actually, it is a thin wrapper around Java, making it look like a scripting language: it has a (primitive) IDE when you can type a few lines of code and hit Run without even having to save the file. Actually it wraps the code around a class and adds a main() call, compiles it and run it in a window.</p>\n\n<p>Lot of people use it for real-time exhibitions (VJ and similar).\nIt has the power and limitations of Java, but adds out of the box a number of nice wrappers (libraries) to simplify access to Java2D, OpenGL, SVG, etc.</p>\n\n<p>Somehow, it has become a model of simple graphics language: there are several applications trying to mimic Processing in other languages, like Ruby, Scala or Python. One of the most impressive is a JavaScript implementation, using the <code>canvas</code> component implemented in Firefox, Safari, Opera, etc.</p>\n'}, {'answer_id': 776104, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Don\'t overlook independent languages in your quest. Emergence BASIC from Ionic Wind Software has a built in DirectX 9 engine, supports OOP and can easily interface with C libraries.</p>\n\n<p><a href="http://www.ionicwind.com" rel="nofollow noreferrer">http://www.ionicwind.com</a></p>\n\n<p>James.</p>\n'}, {'answer_id': 857269, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>As a developer/researcher/professor of 3D VR applications for some 20 years I would suggest there is no alternative (except possibly C). The only way to reduce latency and enable real-time interaction is an optimized compiled language (eg C or C++) with access to a fast relaible 3D graphics library such as OpenGL. While I agree it is flustrating to have to code everything, this is also essential for performanc and optimization. </p>\n'}, {'answer_id': 1519427, 'author': 'sdclibbery', 'author_id': 184281, 'author_profile': 'https://Stackoverflow.com/users/184281', 'pm_score': 1, 'selected': False, 'text': '<p>I have very successfully used C++ for the engine, with the application written in Lua on top. JavaScript is also very practical, now the latest generation of JIT based JS engines are around (tracemonkey, V8 etc).</p>\n\n<p>I think C++ will be with us for a while yet; even Tim Sweeney hasn\'t actually <a href="http://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/sweeny.pdf" rel="nofollow noreferrer">switched to Haskell</a> (pdf) yet, AFAIK :-)</p>\n'}, {'answer_id': 1519509, 'author': 'Tobias Langner', 'author_id': 79996, 'author_profile': 'https://Stackoverflow.com/users/79996', 'pm_score': 0, 'selected': False, 'text': '<p>The best enviroment for your project is the one you get your task done in the fastest way possible. This - especially for 3D-graphics - includes libraries.</p>\n\n<p>Depending on the task, you may get away with some minor directx hacking. Then you could use .NET and <a href="http://slimdx.org/" rel="nofollow noreferrer">slimdx</a>. Managed languages tend to be faster to programm and easier to debug.</p>\n\n<p>Perhaps you need a really good 3D-engine? Try <a href="http://www.ogre3d.org" rel="nofollow noreferrer">Ogre3D</a> or <a href="http://irrlicht.sourceforge.net/" rel="nofollow noreferrer">Irrlicht</a>. You need commercial grade quality (one might argue that Ogre3D offers that) - go for Cryengine or Unreal. With Ogre3D and Irrlicht you might uses .NET as well, though the ports are not always up to date and plugins are not as easyly included as in the C++ versions. For Cryengine/Unrealengine you won\'t have a real choice I guess.</p>\n\n<p>You need it more portable? <a href="http://www.opengl.org/" rel="nofollow noreferrer">OpenGL</a> for the rescue - though you might need some wrapper (e.g. <a href="http://www.libsdl.org" rel="nofollow noreferrer">SDL</a>).</p>\n\n<p>You need a GUI as well? <a href="http://www.wxwidgets.org/" rel="nofollow noreferrer">wxWidgets</a>, <a href="http://qt.nokia.com/products" rel="nofollow noreferrer">QT</a> might be a possiblity.</p>\n\n<p>You already have a toolchain? Your libraries need to be able to handle the file formats.</p>\n\n<p>You want to write a library? C / C++ might be a solution, since most of the world can use C / C++ libraries. Perhaps with the use of COM?</p>\n\n<p>There are still a lot of projects/libraries I did not mention (XNA, Boost, ...) and if you want to create some program that does not only display 3D-graphics, you might have other needs as well (Input, Sound, Network, AI, Database, GUI, ...)</p>\n\n<p>To sum it up: A programming language is a tool to reach a goal. It has to be seen in the context of the task at hand. The task has its own needs and these needs may chose the language for you (e.g. you need a certain library to get a feature that takes long to programm and you can only access the library with language X).</p>\n\n<p>If you need the one-does-nearly-all: try C++/CLI (perhaps in combination with C# for easier syntax).</p>\n'}, {'answer_id': 1951889, 'author': 'oyd11', 'author_id': 237493, 'author_profile': 'https://Stackoverflow.com/users/237493', 'pm_score': 0, 'selected': False, 'text': "<p>Good question.\nAs for the 'making me type far too much', C++0x seems to address most of it\nas mentioned:</p>\n\n<p>auto it = lotsOfThingys.begin()) // ... deduce type, just like in *ML\nVS2010beta implements this already.</p>\n\n<p>As for the memory management - for efficiency - you will have to keep good track of memory allocations, with or without garbage collection (ie, make memory-pools, re-use allocated object sometimes) anyhow, so that eventually whether your environment is garbage collected or not, matters less. You'll have to explicitly call the gc() as well, to keep the memory from fragmenting.\nHaving consistent ways to manage memory is important anywhere.\nRAII - is a killer feature of C++ \nAnother thing - is that memory is just one resource, you still have to keep track of other resources with a GC, so RIAA.</p>\n\n<p>Anyhow, C# - is a nice alternative in many respects, I find it a very nice language, especially the ability to write functional-style code in it (the cute lambda -> syntax, map/select 'LINQ' syntax etc), thus the possibility to write parallel code; while it's still a 'standard curly-brackets', when you (or your colleagues) need it.</p>\n"}, {'answer_id': 1993746, 'author': 'crelbor', 'author_id': 150712, 'author_profile': 'https://Stackoverflow.com/users/150712', 'pm_score': 2, 'selected': False, 'text': '<p>I vote c++0x. Partial support is already available in gcc-4.3+ using the -std=c++0x flag.</p>\n'}, {'answer_id': 3071648, 'author': 'philnext', 'author_id': 359671, 'author_profile': 'https://Stackoverflow.com/users/359671', 'pm_score': 0, 'selected': False, 'text': '<p>Have a look to Delphi/Pascal Object and some exemples :\n<a href="http://www.delphigamer.com" rel="nofollow noreferrer">http://www.delphigamer.com</a> or <a href="http://glscene.cjb.net/" rel="nofollow noreferrer">http://glscene.cjb.net/</a></p>\n'}, {'answer_id': 4265913, 'author': 'Rik', 'author_id': 518630, 'author_profile': 'https://Stackoverflow.com/users/518630', 'pm_score': 1, 'selected': False, 'text': "<p>Java and LWJGL (OpenGL wrapper) has worked well for me. If you're looking for more of a scene graph type library like Orge have a look at jMonkeyEngine which we used to create a google earth type application (see www.skapeworld.com). If you're sensible with object creation the garbage collection is a non issue.</p>\n"}, {'answer_id': 5339700, 'author': 'BenjaminB', 'author_id': 282815, 'author_profile': 'https://Stackoverflow.com/users/282815', 'pm_score': 0, 'selected': False, 'text': "<p>You can look at <strong>Ada</strong>. There is no garbage collector but this language is oftenly used for real-time system needing high reliability. That means less debuging times for your 3D applications.</p>\n\n<p>And, you can also look at <strong>Haskell</strong>, if you don't know the functional paradigm this language will look weird to you, but it's worth a bit of your time. Tim Sweeney (EPIC Inc) is considering this language as a C++ alternative.</p>\n"}, {'answer_id': 5343237, 'author': 'Martin Beckett', 'author_id': 10897, 'author_profile': 'https://Stackoverflow.com/users/10897', 'pm_score': 2, 'selected': False, 'text': "<p>Would 'C' be too obvious an answer?</p>\n"}]
['https://Stackoverflow.com/questions/72931', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9631/']