What Language Do I Use?
Your choice of language will affect the rest of your project, and it's impossible to change languages in the middle of a project without a complete (or at least very extensive) rewrite, so it is not a choice you should make lightly. It is also not a choice that you should allow to be colored by your own personal preferences or the urging of friends. Your choice of computer language for your project should be well-researched and pragmatic. What counts most is the quality of your results and not that the language be worthy of your programming skills.
This article will cover some of the languages that are popular with game programmers. This list is neither complete nor deep. This article is intended to give you a bird's eye view of the most popular game development languages out there along with a short overview and a few situations where they would be a good or a poor choice for a project.
One final note before you read the list. This list does include plenty of terminology that might not be familiar to you as a beginner, and there simply isn't enough space to define everything. It is recommended that you keep Wikipedia handy for the terminology with which you are not yet familiar.
The C Programming Language is either the direct parent or a heavy influence to every other language discussed in this article. While it was itself derived from a couple of other languages that have fallen into disuse, C is now considered to be one of the "root" languages of computer science. Some other languages that predate C (COBOL, FORTRAN, Lisp, Smalltalk) are still in use today and owe nothing to C, but just about every language that's been produced since the 1980's owes at least some of its syntax to C.
C is a classic "brace language", which is to say that it's a structured goto-less language that uses the open and closed curly-braces to group statements together. It's a structure that's repeated in many of the languages that follow (C++, Java, C#, ActionScript, PHP). One advantage of the endlessly-imitated structure of C, braces and otherwise, is that once you understand how things are done in C, you can carry them over to the other languages with almost no changes. The if(), while(), and for() statements in C and PHP, for example, are basically identical. For that very fact alone, it is recommend that you familiarize yourself with C syntax, as it is something that you can keep with you.
Advantages: C is good for writing small fast programs. It is easy to interface with assembly language. The language itself as well as the library routines are standardized, so moving programs to other platforms can be a straightforward process if you plan ahead.
Disadvantages: The ability to write small programs quickly also works against C, as C is not normally used for object oriented programming[note], which is a method of structuring your code that's better suited to large programs with distributed development, and large C programs can grow disorganized easily. While many very large projects have been written in C (Unix, Windows, Oracle), managing a large C-based project requires more discipline than in languages that are built around more modularity.
Portability: While the core of the language itself and the ISO function calls are very portable, these calls are limited to control flow, simple memory management and simple file handling. Modern user-interface constructs, like menus, buttons, dialog boxes, etc., are not portable between platforms, so you will need to either write your code to work with a third-party UI toolkit or plan to write your user-interface twice.
While the language was ahead of its time when it was created, the C library is showing its age. Many non-trivial library functions, like memory management and strings, have a simplistic syntax that has been significantly tuned up in the language's successors.
While C has been redesigned and re-standardized several times to keep up with the times, some of the syntax is counterintuitive by necessity. Some of the quirkier language constructs remain for the sake of compatibility with existing code.
Suitability for Beginners: Not very good. While the core of C is fairly compact and easy to grasp, many of C's library calls are antiquated and are easier handled in some of its successor languages.
Resources: While Kernighan and Ritchie's The C Programming Language is the "classic" book on the subject, the book does cover topics fairly quickly, and it might be too quick for a rank beginner at programming. Other well-recommended books include C How to Program, C Programming: A Modern Approach, and C Primer Plus
C++ is C's most established "child" language. It was designed in the 1980's as an extended version of C with support for "classes"[note], which are abstract data structures that aggregate primitive data types and algorithms into something that is better able to model real-world (or in the case of games, simulated-world) objects. C++ classes also support the concept of "data hiding" in which you can hide the underlying implementation of an object from the rest of your program. While this method seems a bit inscrutable, it is extremely useful when programming in a team environment. It allows you to agree on how the object's interface is intended to work without regard as to how the object works internally. It's a bit like saying "I'm giving you a job, and I don't care how you do it as long as it gets done, and the result looks the way I want".
Advantages: Supports the object-oriented (OO) paradigm very completely, which is much better than C for supporting large projects. Unlike C, it contains a very well-designed library of common data structures and algorithms.
Disadvantages: The syntax of C++ has grown larger and more complicated with each iteration, and the language is absolutely byzantine now. The syntax lends itself very easily to abuse and, while the language does support team programming very well, its huge and deep syntax can make code difficult to read.
Portability: Despite its roots in C, C++ has better portability than C[note]. This is because most modern portability toolkits are implemented as C++ object libraries rather than the old-style C function libraries. In addition, C++'s standard library and very useful Boost library is very standardized and cross-platform despite the complexity of both.
Suitability for Beginners: While the memory management and I/O operations in C++ are significantly easier to understand than C, C++ has a pretty high learning curve just from its sheer size. Thankfully, one doesn't have to learn the entire language to be productive with it.
Resources: A perfect beginner's book for C++ is C++: A Dialog by Steve Heller. It's very well-paced and approachable, and it's perfect for beginning programmers.
For a more comprehensive approach, Bruce Eckel's monumental two-volume Thinking in C++ series will tell you all you need to know about C++ in only 1,600 pages.
As an added bonus, these books are available for free download. Google for them, and you should have no trouble finding the official sites.
C or C++: Short of "DirectX or OpenGL", this is one of the most-asked questions when getting ready to learn the language. C++ is, with a couple of very minor exceptions, a proper superset of C. That means that all that C does, C++ does the same. Every C++ compiler will also compile C, and C-only compilers are very hard to find nowadays. While those facts might make it seem logical to start with C and then learn the "rest" of the language later, it is a better idea to learn classes and OO programming early on rather than having to "unlearn" techniques that don't model the environment (real or simulated) very well.
Objective-C is an object orientated, strongly typed programming language with a dynamic runtime. In it's nature, it is a superset of C. It inherits the majority of it's basic syntax rules from C, while having some more major changes to the structure as well. That for instance would include method calls, overall definition rules and so on.
Objective-C is the primary language for MAC OS X and iOS programming and is an Apple exclusive. It supports a wide variety of development techniques, functionalities, libraries and many other bonus features that make this language stand out (for more information, see reference). The language supports a really wide range of built-in libraries for handling 2D and 3D graphics (OpenGL based) which can help a junior game developer in building his/her first game bu using a powerful, yet native solutions. Other libraries help game development as well, especially for mobile. Another standout feature is the reference counting garbage collector, working in a close collaboration with the very sophisticated memory management system (see reference).
Advantages: Objective-C is a powerful superset of C and can produce and run very powerful and flexible applications. It can utilize C/C++ code and through that it is easy to port new projects and extend the power of already existing such. The language possesses a really wide variety of helpful libraries and one of the best development environments in the face of Xcode. This is a powerful OOP language that can be used in many ways.
Disadvantages: Objective-C is an Apple exclusive, thus you need an Apple computer, running the latest version of Mac OS X in order to develop your applications. Another thing to note is that some of the syntax rules of the language can end up being confusing for the beginner to intermediate programmer. The method calls are far from the standard, the class definitions are also going to cause some confusion for beginners that have no experience in C/C++. Something else to note – knowledge of memory management on a higher level is absolutely required if you plan to develop apps for iOS.
Portability: There is none. What ever is written in Objective-C stays within the Apple products. You cannot port an Objective-C project to another platform without completely re-writing it in another language. The bottom line here is – Objective-C is only suitable for Mac OS X and iOS development.
Suitability for Beginners: Objective-C is not the most beginner friendly language, though it's not the hardest one as well. You'll have an easier time learning C# or Java, yet getting proficient in Objective-C is relatively easier then C++. A beginner will most certainly need to put in a lot of reading into concepts such as memory management, so on and so forth and that can be a painful process to go by if you are just starting out, however it will pay out in the long run.
Resources: Aside from the official Apple guides, there are a lot of free e-books on onlineprogrammingbooks.com - http://www.onlineprogrammingbooks.com/objective-c/
Objective-C memory management:
Objective-C for game development:
Objective-C compared to Java:
Objective-C compared to C++:
General iOS development compared to Android development:
Java is, for practical purposes, the first "post web" language. While some languages like Perl suddenly found their string-handling capabilities to be a natural for retrieving values and sending display-able HTML to web browsers, Java initially found its footing in the browser itself, first in the very interesting but monumentally quirky HotJava browser (written in Java itself), and later in the form of extensions for existing browsers.
Java, while on its face structured similarly to C and C++, behaves very differently on the "back end". The Java compiler, rather than compiling Java source code to native machine-code, compiles to "bytecode" that is run by a Virtual Machine or VM. The Java bytecode is an assembly language of sorts, but it is not an assembly language that is married to a particular processor. The Java VM, which is actually a runtime interpreter of bytecode, will then interpret the bytecode for your machine's target processor. The advantage of this approach is that Java bytecode can be moved from machine to machine and executed without changes provided that the target machine has a compatible Java VM or, as Java promised, "write once, run everywhere". The disadvantage of this approach is that Java bytecode is not native machine code, and while technologies such as "just in time" compilers can improve VM performance, the fact is that you're doing some level of interpretation at runtime, and that does entail a minor, but measurable performance hit.
The other disadvantage is that realities of Java have not lived up to the language's early promises. While the idea of executing games inside web-pages captured everyone's hearts almost immediately, the reality quickly set in that Java VM's aren't as compatible with each other as they should be, and a Java application or applet written on one machine using a particular VM may or may not run nicely on another machine with another VM version. "Write once, run everywhere" was snarkily renamed "write once, port everywhere", which is to say that once you finished writing your Java code and it's running beautifully on one platform, you then had the non-trivial task of making sure the application will actually run well and look nice on all systems.
The third disadvantage of Java came with its GUI. While the first "pass" at making a Java GUI used native OS controls (buttons, scroll bars, etc) and was reasonably small and fast, it wasn't very deep. The next pass, Swing, looked better but performed worse and was entirely different from the original controls. And, worst of all, Sun (Java's parent) was slow to add OS features that had been in existence in the underlying OS for years, like support for ClearType font rendering. Hence, Java applications always seemed to look a few versions away from state-of-the-art.
There is one place, though, where Java took a good hold and Java's advantages outweighed its disadvantages, and that was in server programming. One big advantage of a VM is that since it's not an actual processor but just a simulation of one, crashing the VM isn't much of an issue. If you do manage to completely confuse the Java VM, that doesn't really affect the parent operating system, and you can close and restart a session without having to reboot the entire machine. Couple that with the fact that Java's memory management scheme is a generation evolved from that in C++ and C, and suddenly problems like allocating memory without releasing it back to the system became much less of a problem. And a system like this is perfect for a server environment. A server can pop up and kill VM's as necessary without affecting the underlying OS. Also, the GUI problems don't really apply, as it doesn't matter if your server software doesn't look spectacular unless you just want to impress server-admins. Today you'll find many commercial Massively Multiplayer games that use Java on the server side. A good example would be the multiplayer games by Three Rings that are fully Java on the client as well as the server-side.
Another place where Java has very strongly caught on is in the mobile phone market. J2ME[note] (Java 2, Micro Edition) is a "miniature" version of the Java VM with a significantly truncated class library which is designed to run on mobile phones and other small devices. In fact, if you include the mobile phone demographic, Java is one of the most popular platforms in existence.
Advantages: Java's Virtual Machine coupled with its memory management and automatic collection of no-longer-needed memory allows you to make software that is very robust and crash-resistant. It also has a strong tradition of extensive documentation[note].
Disadvantages: Java's "write once, run everywhere" promise wasn't fulfilled. The Java class libraries have been rewritten multiple times without removing old calls, so while the libraries are very backward-compatible with old code, there seems to be three ways of doing everything, all but one of which are discouraged as being "obsolete".
Portability: Fairly good, but not as good as it should have been. Making an application in Java that is portable and uses the underlying OS's latest features is almost as difficult to do in Java as in C++.
Suitability for Beginners: Reasonably good. While figuring out the "right" way to do things without bumping into a deprecated object is a bit of a pain for beginners wading through the language, the core of the language itself is well-designed and easy to understand. Also Java is a standard language for many university courses.
Resources: Oracle Inc., the Java authority, has plenty of great resources for Java programmers.
.NET Languages (specifically C# and Visual Basic)
.NET (pronounced "dot net") is basically Microsoft's answer to the Java VM. Actually, .NET is the name for the overarching technology. The actual VM's name is CLR (common language runtime), and everything that was said earlier about the Java VM also applies to the CLR with one significant exception: the CLR was designed from the ground up to not be "married" to a single language, as Java was. And because of this, there are a whole host of languages that use the CLR to do the back-end processing. Everything from ancient legacy languages like COBOL and FORTRAN to modern languages like Python can target the CLR. Mind you, some of the CLR projects out there are little one-man projects, so don't get too excited if you find your favorite language in a CLR version, as some of the compilers are far from mature.
C# and Visual Basic, both developed by Microsoft, are the most popular CLR-based languages. C# is a language clearly derived from Java, and it shares about 90% of Java's syntax despite sounding more like something derived from C or C++. C# does have several nice language extensions that Java has been slow to add as well as a completely rewritten class library.
Visual Basic, which was briefly renamed VB.NET, is a CLR implementation and replacement for Microsoft's established and popular Visual Basic environment. While it is still called "Basic" and is no longer in all-caps, it bears very little resemblance to the old BASIC interpreters that were burned into the ROM of just about every computer sold in the 1980's. The syntax is now structured similarly to the other languages in this list, although it still doesn't use braces to group statements. It also uses the more object-oriented "dot notation" to call functions rather than the large function library of the pre-CLR versions of the language.
Advantages: While Java does have a couple of minor efforts to compile languages to the Java VM, the CLR is designed from the ground-up to support this. Hence, there are several CLR-based languages, and it's relatively easy to get them to communicate with each other.
The .NET technologies are very well-supported by Microsoft's Visual Studio environment, which is a very mature and feature-rich development environment.
C# is the premier programming language for Microsoft's XNA technology, which is a method of making games that are portable between Windows and the XBox 360 game console.
Disadvantages: Unlike Java, CLR applications can't run as applets within web pages. While the "Silverlight" technology does allow this, it's fairly late to the game and is not entrenched in browsers the way that Java and Flash are. Silverlight has also been discontinued after release 5.
CLR-based applications are much less portable than they should be.
Portability: While there are third-party efforts to port the CLR to operating systems other than Windows, the efforts in that direction are significantly smaller than the work being done in Windows. So while you might be able to create a very robust .NET application for Windows, your Mac and Linux efforts won't be nearly as smooth.
Suitability for Beginners: Good on both counts (C# and Visual Basic). Both languages are straightforward and easy to understand. In addition, their tight integration with the Visual Studio environment makes setup fairly easy.
Flash and ActionScript
Flash is a bit of an unusual member of this list, as its roots do not exist with the language itself but with an animation tool. In the 1990's, a couple of developers were dismayed at the size required to display animated graphics on web pages and the method by which they were displayed, so they developed a browser plug-in called "FutureSplash" as well as a drawing and animation tool that could create very compact vector-based animations. Macromedia, already a player in the interactive web-business with their Shockwave plug-in that could play content from their Director animation tool, purchased FutureSplash, renamed it "Flash", and proceeded to take the browser animation market by storm.
A few years ago, Adobe introduced a tool called "Flex" which was an attempt to "grow up" Flash into something more suitable for building browser-based user interfaces and RIA (Rich Internet Application) content rather than just animations and games. While not a replacement for Flash, Flex is better suited for building user interfaces, as it is an XML-based programming language with rich UI support rather than an animation tool with a built-in programming language.
Advantages: Flash's integrated drawing and programming tools make programming web-based games absurdly easy. The Flash environment, while not having the pedigree of Visual Studio, is extremely feature-rich.
Disadvantages: Flash, while a great environment for one person, does not support team programming very well.
While the Flex compiler is free, the very nice FlexBuilder Flex content-creation tool is not.
Unlike the other languages on this list, ActionScript is a client-only technology. While some kind of server-side ActionScript interpreter might prevent you from having to learn a separate server language, such a thing does not exist.
Portability: Flash runtime players are available on Windows, Mac, Linux, several breeds of mobile phone, and some game consoles. Not all devices support the same version of Flash, though, so you will need to learn the capabilities of each version and what you want to target before you get started.
Suitability for Beginners: Excellent, especially with its aggregation of drawing and animation tools. Although such ease of building in the Flash environment will not apply to other languages. A technique or build tool used in C++, for example, will likely have an equivalent in Java and vice-versa. The Flash development environment is unlike all others.
Resources: Just like Microsoft is one-stop-shopping for all of your .NET needs, Adobe is the place to go for Flash.
Python, unlike the previously-mentioned languages, did not start out as a large corporate or university project. It was much more of a grassroots effort among university students and, later, among people in the industry who liked the language's structure as well as its lack of legacy features. The language itself is fairly compact and is easy to use. It is also easy to embed a Python language interpreter into existing projects, which is why you'll see Python as an embedded scripting language in many games.
Python also functions well as a server language as it features many of the server-friendly attributes of Java. In fact, Python compilers exist that can compile Python code to both the Java VM and Microsoft's CLR. Many services that you would recognize (YouTube, Google, and Yahoo) use Python extensively for back-end processing.
Python is also becoming quite popular in the gaming community with the user-supported PyGame library. PyGame is an object library that abstracts the well-established SDL cross-platform graphics library into something friendly and easy-to-use from Python. Several impressive arcade games have been written entirely in Python.
Advantages: Free and open-source. Very dedicated user community. Integrated fully into Google AppEngine, which is Google's "pay to play" processing server.
Disadvantages: Virtually everything is handled not by a large corporation but by its user-community, so it might be a hard-sell to get a company to sign off on a Python-based project, although some very big players are now invested heavily in Python so Python now looks like much less of a "hobby language" than it used to be.
Portability: Pretty good. Most of the third-party libraries made for Python are built around portable technologies like SDL and OpenGL, so it's not too difficult to write something in Python that will run on several platforms.
Suitability for Beginners: The Python language has an easy-to-follow syntax and is easy to learn. In addition, there are several good community-written tutorials out there.
Resources: Python.org is a well-organized home for all things Python. It is also the home of many active community forums where you can get your questions answered.
There are two things that you must know about assembly language.
- The name of the language is "assembly". The name of the tool that converts assembly language into low-level machine code is called an "assembler". It's a common mistake, even among experienced programmers, to call the language "assembler". So please start out on the right foot by calling the language by its proper name.
- Assembly language is, by default, the smallest and fastest language in this article. Since it is not a high-level language but is actually a mnemonic representation of your CPU's instruction set, there is nothing written in a higher level language that can't be done faster in assembly
And given fact number two above, you might think your search is over. After all, if a language is necessarily the smallest and fastest of the bunch, why not use it? In fact, why do other people bother with C or C++ or anything else when you can write your code in assembly and get the best results by definition?
That's because the term "best code" doesn't just refer to the raw speed and size of your program. There is the quality of readability, as you might need to hand some of your code over to a colleague so he can work on it. There is the quality of portability, as you might need to move your code to another operating system or hardware architecture. There is the quality of maintainability, which is the need to easily fix problems at the close of the project. There is the quality of abstraction, in which you can write code in terms of moving a character down a hallway rather than manipulating numbers in locations in memory.
And in all of those factors, assembly language comes in dead last. Assembly language is very difficult to read and maintain. Unless meticulously commented, it is of little use to anyone else inheriting the code. Fixing bugs and extending the existing code is difficult at best. You have to keep a constant eye on portability, lest you end up writing code that won't even run on different processor models by the same manufacturer. And the closest you'll get to "move the alien ten pixels to the left" are some register updates followed by several instructions to call the bitmap-display function.
In practice, assembly is almost never used for complete games. Assembly, when it is used, is used in parts of programs that do a lot of calculations and are called a lot of times. Sometimes whittling a few machine-instructions out of a function that is called millions of times can provide enough of a benefit to make the extra work worthwhile. But this is a process that isn't undertaken from the beginning of a project. It is something done in early testing, after determining where the programming bottlenecks actually are.
Assembly language is not for the faint of heart, and if you're reading an article to try to figure out what language to use, then you should probably look elsewhere.
Advantages: Is the fastest and most compact way to go if you know what you are doing.
Disadvantages: If you are reading this, you probably don't know what you are doing. Prepare to spend a long time learning a million little tricks to shave off processor ticks here and there.
Portability: Worse than bad. Unless you are programming for the baseline processor, your programs might not even run on other "compatible" processors. For example, some special instructions on AMD processors are not available on Intel and vice versa.
Suitability for Beginners: Run away.
Resources: Assembly Language for Intel-Based Computers is well-recommended if you intend to write for Intel processors. If not Intel, check out the makers of your target CPU for technical resources.
While many of the languages mentioned above will work nicely on the server, some of the technologies around which they were built are rather archaic, and much smoother easier-to-use solutions are now available. The original standard for writing a custom back-end for web-pages was called CGI, and it was a simple standard for running a customized executable on the server-side, passing it data from the page that called it, and collecting text output and returning it to the user. And while it was simple to implement on the server-side, it really doesn't model the interactive experience as the web is used today, and CGI-based solutions for interactive web-applications can be clunky at best.
PHP was one of the first true "embedded" scripting languages for the web, and in many ways it revolutionized the way that pages are scripted. While PHP can operate as a scripting language that takes input from a web form, processes it, and returns output, its real strength is its usage as a hypertext preprocessor. PHP, once configured to work as a preprocessor for a server, can process code that's embedded the page itself. So rather than writing a piece of standalone code that will, for example, print out the current date in a page, you can just embed the PHP code directly into your web page that prints the date, and the code will be quietly replaced with the resulting text as it is sent to a browser. PHP also added a library of native commands to communicate with the free and powerful MySQL database, making storing and retrieving persistent data easy.
Another thing that made PHP instantly popular was the price. It was free, thus cementing it in the popular server configuration known as LAMP (Linux, Apache, MySQL, and PHP). The combination of these four technologies gave beginning or low-budget web designers an easy-to-use, scalable, and very powerful web setup for free. And as a bonus, it could run on low-cost hardware. And this fact was not lost on web developers. Today there are a large number of free or low price PHP scripts to perform just about any task, from simple user databases to complete "website in a box" setups.
Not to be outdone, Microsoft quickly put together their own PHP-esque configuration based entirely on Microsoft's technologies, namely Windows, Internet Information Server (Microsoft's web server), CLR, and SQL Server. While far from free and not in PHP's league in the breadth of third-party scripts available, ASP.NET does have the advantage of all the tech support money can buy as well as support for languages other than PHP. If you're familiar with Visual Basic on the client side, for example, you can use it on the server-side with ASP.NET.
But if you're working within a budget, a LAMP setup will likely be a better fit.
Ruby on Rails
Ruby on Rails (often just called "Rails") is not itself a programming language but is a class library built with the Ruby programming language. While Ruby itself is a not-very-revolutionary object-oriented scripting language that owes its heritage to both Python and Perl, it is the Rails library that makes the system revolutionary. The Rails library fully integrates the MVC (Model View Controller) paradigm and is designed to prevent as little repetition of technique as possible. And this does allow you to build a fairly rich server-based system with a minimum of code. And the Rails folks will proudly show off web-forums and social networking sites that have been written in an absurdly small amount of code.
Like PHP, Ruby on Rails is free.
Other Languages That Are Worth Mention
The sections above cover most of the languages that have a pedigree in the game development world, both on the client and server. That is to say that large scale or popular games have been written using these languages. There are, however, a couple of interesting technologies out there that, while not yet established as first-class languages for games, show lots of promise. It would not be surprising to see these languages score some major projects in the future.
D is a sort of "unofficial" grandchild of C, C++, and Java. It is the brainchild of Walter Bright, who is one of the pioneers of C and C++ compiler construction on PCs. Growing frustrated with the ever-growing class libraries as well as the fanatical need for backward compatibility, Mr. Bright decided to build something from the ground-up that took the best features of C, C++, and Java while jettisoning anything that didn't have a very good reason for existing. And the result was a language that was tighter and easier to learn than its "parents" without sacrificing important features or runtime speed. D is what happens when you take language design away from the realms of the committee.
While D does jettison backward compatibility in the name of simplicity, it does have excellent methods for communicating with C code, so if you have a third-party library or some C source code that you are loath to rewrite, you can still talk to it without much difficulty.
That is to say that D would be the best of all worlds if it gained more support. It simply doesn't yet have the huge libraries of code, wealth of tools, and base of user support of the other languages. Hopefully its support will grow and it will receive the attention it deserves, but that will take some time.
Early on it was clear that this article would not reach a satisfactory conclusion as to what language to use. Fact is, there's very rarely a single solution that will solve all problems. Hopefully this list will at least whittle your choices down to two or three good candidates. The rest of the research is up to you.
Thankfully, virtually every solution mentioned above has a free implementation, so you can try out these languages and choose the one that you think will best suit your project.