Monday, November 03, 2008

Reflections Roundup Series nº 1:

The C++ Winter, Game Development Environments and Programming Languages

Meta: Reflection Roundup series are ramblings in one or multiple related subjects where i try to expose my point of view (YMMV of course, so comment!)

Before starting this post, remember that the language i'm talking about is C++(not ANSI C or Objective-C).


My relationship with C++ can be described as a 3-instance date that ended with me putting it up in the refrigerator. What always drove my attraction to C++ is the fact that it's intensively used in the game development world.... being the gamedev wannabe that i am, i said "I must learn it at any cost!" and started reading and gathering information in order to understand the language's mechanisms and their rationale.

When i got committed to a game project a few months ago(that blew up unfortunately) , I've gone through Scott Meyer's Effective C++ [1] to acquire a deeper understanding of the language, its pitfalls and ambiguities.
What I've realized after reading half of the book is that you gotta practice defensive programming all the time. In some situations i bet there are more than 5 ways to add undefined behavior to your program in a single expression. That's a tough thing... because the complexity of the language easily surpass the complexity of the problem being solved and i'm sure that this have a serious impact in productivity.
Spice it up with a large source tree,complex builds, and multi-platform code[2] , roast it intensively with the multicore crisis and you can realize that it's not a very nice place to be...


I can't imagine how these guys manage to be productive... and i would really love to spend one day watching the spartan work of a Sr. Programmer of the game industry, so i could bring my opinion closer to reality.
I'm not the best to speak on its problems... there are people that faced them on a daily basis for some time and can clearly discuss on the subject [3]

Some remarkable guys built something different a while ago. Naughty Dog, the softhouse behind famous Playstation 1 and 2 titles like Crash Bandicoot and Jak And Dexter managed to develop their own environment for game development. It consisted of a lisp DSL that allowed fluent rendering description procedures(probably allowing SIMD assembly inline as well) and game entities management. All of this in the top of a REPL that Emacs clients would connect to send code upgrades on the fly!
This genius environment [4] , structured by Andy Gavin (an MIT-brewed-lisp Jedi) had its flaws as well. Even sounding like the wet dream of most game developers it didn't solved all the problems. With an environment like this ND was swimming against the current, becaus most of the vendor tools were aimed for the C++ market. They had to maintain lots on in-house code, and most of the core stuff was centered in Andy. The result was : When Andy left, there was no further interest to keep improving the technology, so, everything was dropped off in favor of C++[5]
. Another potential case of Philip Greenspun's 10th programming rule.

Even not being the "happily ever after story" it's a proud example where fearless research and exploration of different technologies can led small companies to Beat the Averages and deliver high quality products. Few people tends to pick change instead of cold comfort.

Tim Sweeney, the architect behind Epic's Unreal technology already expressed his ideas of a programming language that would be ideal for games and suggested some good stuff that would be of high value for game developers and other kinds of multimedia/real time apps. Some programming idioms in the presentation may remind you of Haskell (list comprehensions) Erlang and the newborn Clojure (concurrency features like Software Transactional Memory and Actor-based concurrency). The use-or-not-use garbage collection may remind you of Digital Mars D, where you can choose between garbage-collection and manual memory management.
Speaking on D, Andrei Alexandrescu exposed recently the new functional mechanisms to be implemented in D. For those who don't know him , he's the author of a famous C++ template voodoo book[6] and he's currently assisting on the design of D. He surely know what pissed him off in C++, and what would he do to improve it.
C++0x is intending to employ functional constructs as well, but the question is how many 8 years will take for compilers to catch up with the new standard.


It's notable that developing a AAA game is risky business all the way, and the best way to reduce risk is through the use and development of tools that assist in controlling complexity, allowing the developers energy to be better employed in problem solving and design innovations instead of "which side of my declaration the * should go this time?"

Multi-platform game development urgently needs a language/platform to make this happen. I think its past time to appear a massive turnaround in the area (much like Java and Ruby on Rails as internet apps development platform at their respective boooms) The funniest thing is that even games being the type of application responsible for edging technological improvement in the area of PCs and specialized appliances, very little innovation is exposed in terms of programming languages and runtime environments for development and deployment of games... My vision may be distorted , but it looks that stuff is pretty much done the way it was like 15 years ago , but in larger scale.

C++ is still on the run, and there are loads of people using it.
It's kind of a "Double-Edged Gunblade of the programming languages where you can cut your neck and shoot youself in the foot in just one move.
It's a complex and potentially great tool in the hands of a programmer that features a full C++ runtime embedded in his brain.


Me? I prefer to keep ANSI-C, Objective-C, Ruby and Lisp in my weapon box , and you?



References:

[1] Meyers, Scott(2005) Effective C++, 55 specific ways to improve your programs and designs

[2] A pal from Australia that works in the game industry once told me that their C++ game codebase was tweaked to compile/run in more than 3 platforms... imagine the entanglement of #ifdefs and other preprocessor code bending to make it happen

[3] The C++ FQA is a good digest of most common CPP pitfalls. For a more more "first-person-narrative-style " this guy exposes his pain , and how he gave up on C++ and decided to code in a Object Oriented C Idiom.

[4] Gamasutra has one of the few articles around describing how the DSL and the development environment was

[5] A while ago Naughty Dog announced their return to Lisp in their game development platform, using their experience from GOAL to improve their environments. Way to GOAL! :D

[6] Alexandrescu, Andrei(2001) - Modern C++ Design: Generic Programming and Design Patterns applied

Labels: