From GPWiki
For as long as there has been choice, would-be programmers, in our case game programmers, have wondered what language they should start with. It isn't always an easy decision, and everyone has different advice to give. There have been numerous arguments on the subject that tend never to get anywhere. The truth is that there is no "Holy Grail" language to start with. The best way to decide on a language is to enumerate the points you want to have in your language of choice and from that make a decision on which language has what you want. This tutorial should help you do that.
Things To Consider
There are many, many points that could be considered in choosing a language to work with, but which ones are relevent to specific programming needs or most important is an arguable area. It all depends on what you want to do with your language.
Power - the word power in the sense of a programming language is the features that it supports that can be useful when programming. These can include support for pointers, complex data structures, advanced mathematic operations, built-in interfaces to the OS and/or filesystem, error handling/exceptions, overloading, inline assembly, and object oriented programming. The list can go on and on. Some of these items are more important to game programming than others, and the importance and usefulness of some is arguable. The best way to get acquainted with a language's power is to do research on it and its features.
Portability - portability is the ability of a language to compile for multiple platforms, different operating systems and system architectures. This is more important to some people than it is to others. Some people are fine with their games running only on one platform, usually Windows, but others, usually people who use alternative OS's like Linux or OSX, want their games to run on their own platform and others. If your language only works on one platform, there's no hope getting your games to run on anything else without completely re-writing the code in another language.
Speed - speed of code execution is one of the most arguable of points for amateur game developers. The truth is that most amateur games can get by with a very slow language, usually due to their low graphical complexity. But it can't hurt to use a very fast language, if just in case you want to be capable of programming an advanced game at some point.
Ease of use - this is an important point to consider, especially for a new programmer. If too difficult a language is used to start with, it is easy for a new programmer to be intimidated and give up learning it. A difficult language can also increase development times with bugs resulting from the misuse of the language. Any language, however, can be easier to learn if it is a cousin of a another language. For example, C# can be picked up easier by some users if they have learned Java, its closest cousin. See Generational List of Programming Languages
Library compatibility - very few languages have the inherent ability to draw images to the screen and play sounds and other things necessary to the programming of games. So we have to use an external library to do it. Some languages have better and more libraries that work with them than other, usually more obscure, languages.
Object Oriented Programming (OOP) - is a method of organizing code into objects. Rather than looking at code from a functional standpoint with function making calls to every other function, code is grouped into structures and classes. Where a purely functional program might be represented by the pseudocode
function move {
(contents of function)
}
function shoot {
(contents of function)
}
An object oriented program would group those functions together and create objects of the created class could be represented
class enemy {
function move {
(contents of function)
}
function shoot {
(contents of function)
}
}
To use the class, an object is created in the form of the class and its elements are called.
main function {
monster is enemy
monster do move
monster do shoot
}
In this way, we can have many monsters without having a whole bunch of variables cluttering up our namespace. The problem with this hierarchical structure is that it can lead to rewriting the same functions several times for different classes, possibly only making a few modifications to each. Many languages implement inheritance, where one class can recieve certain functions from a parent class, but this in itself has the problem of not allowing minor adjustments to member functions.
Languages
There are many, many languages out there, and this tutorial will only cover a few of the most popular. Most of the ratings given here could be argued on and on. An attempt has been made to make them as unbiased as possible, but there will always be people and cases that suggest otherwise. Read and use these ratings with caution.
It's highly suggested that you try out a few to see which ones you like, as personal taste often has much more to do with a person's favorite language than any particular attribute of the language itself. This page is also by no means complete. If you find another language you like better, try it out!
C/C++
C and C++ will be mentioned first since they are without a doubt the most common game programming languages. They have an interesting relationship: C++ is C with tons of extra features. So, theoretically, a standard complying C program should compile on a standards complying C++ compiler. However, there are SOME exceptions. For example, certain keywords exist in C++ and don't in C, so in C you can have a variable that is called... for example, "new", and in C++ you can't because "new" is a keyword. C/C++ might not be the right language for a first time programmer because it can be pretty frustratingly difficult at times.
C
C was developed in the 1970's at Bell Labs by Ken Thompson and Dennis Ritchie. It is extremely minimalistic and has been called "portable assembly."
- Power: Medium - Supports plenty of great stuff, but not anywhere near like some languages.
- Portability: Extremely High - Probably the most portable language there is. Most OS's are written in C and one of the most basic things an OS has is a C library.
- Speed: High - As is said before, it is a very light language that runs very fast.
- Ease of Use: Very Low - C leaves management of memory up to the programmer. It is often said that with C it is very easy to shoot yourself in the foot.
- Library Compatibility: Medium - High - Lots of low level libraries are written in C themselves, but other higher level libraries use C++ instead.
- OOP: No support built into language - C doesn't have the capabilities to automate OOP. The only way it can come close to the OOP is by simulating it. This is significantly more difficult than it might be with a OOP language, but it is used by some people. To most people, this is not really considered an OO language. It wasn't intended to be one, and in most people's programming, it isn't.
C++
C++ is a bit newer than C, it was developed in the 1980's by Bjarne Stroustrup as an extension to C and became an ISO standard in 1998. It is a much more complex language, including some of the most powerful library-writing facilities of any procedural or OO language.
- Power: Very High - Has everything C has plus very advanced OOP, templates, overloading of functions and operators, exception handling, and a heap of other useful stuff.
- Portability: High - Not quite like C, but will compile on basically anything you'll probably ever want it to run on.
- Speed: High - Just about as good as C.
- Ease of Use: Low or Medium or High - Depending on which parts you use. You can use C++ just like C, since it's very nearly a perfect superset. However, you can also use its extremely elegant libraries--without needing to understand all the details of their implementation--to program extremely easily. On the other hand, it's been said that if you shoot your foot in C, "It's harder to do it in C++, but when you do shoot yourself in the foot, it blows your leg off."
- Library Compatibility: Very High - Basically everything should work with C++. There are many widely used APIs (Application Programming Interface) available to a C++ programmer. One of these is DirectX, which is used in the development of many commercial games. However, it is exclusive to Microsoft Windows, and is also difficult to use. OpenGL is the cross platform alternative to DirectX. Another, much easier alternative is SDL. It is cross platform, and only requires the SDL runtime libraries to be installed on the target machine. It is also easy to use. Allegro is a similar alternative. Note that all of these will work with C as well.
- OOP: High - Has full OOP support, but it doesn't force you into OOP like Java or .NET.
C and C++ tutorials
.NET
.NET is a very complex system first defined by Microsoft but now being ported to *nix and Macs with the Mono or dotGnu projects, both of which show a lot of promise. A lot of people seem to not like it, probably because they associate it with Microsoft, but it really doesn't deserve it. It is plenty fast and potentially portable. The only real downside is that the end user might not have Microsoft's .NET framework or Mono installed on their system. It is a bit of a large download for people with a slow connection to the internet. But it shouldn't be too much of a problem eventually as .NET gets more popular. The .NET framework is an extremely large API that can do most things that the casual developer needs to do. There are several different languages that use .NET: VB.NET and C# are the main two, with ports of most other major languages (even ADA).
- Power: High - In addition to supporting VB.NET and C#, C++/CLI or Managed Extensions for C++ support all and more of the features of unmanaged C++.
- Portability: Medium - I talked about the .NET Framework and Mono in the introduction. Both Mono and dotGnu work with all but Microsoft specific parts of the framework, and progress is being made in implementing these parts too. On the other hand, enough is implemented already for Game Development, and these parts of the code can be handled by SDL.Net.
- Speed: Medium - High - There's a lot of conflicting information on the speed of .NET. From what I can gather, it is almost as fast as C++. There is a slowdown at the beginning of the very first execution, when the .NET code is being compiled into native machine code, but other than that, it's pretty good in this area. It is also possible to compile the program at installation to avoid this possible slowdown. Also, other variables depend on what version of the .NET framework you're using, v2.0 (on Windows) comes with .NET Runtime Optimization Service, while v1.1 (and Mono) requires on-the-spot compiler optimisation.
- Ease Of Use: Medium - High - Everything is made pretty easy to do with .NET. The biggest hurdles for most programmers are learning the intricacies of OOP and getting familiar with the huge .NET framework.
- Library Compatibilities: Medium - High - There is tons of functionality in the .NET framework, and many major game development libraries have been ported to .Net. Check out Managed DirectX for Windows game development, or the SDL.Net (NOT SDL_Net) and TAO OpenGl ports of their respective libraries. Can also interop with all existing COM code (ie ActiveX and VB6 libraries), and other DLLs (called unmanaged code) with little to no effort.
- OOP: Very High - Supports every feature of OOP that you would ever need, and the whole language is based on OOP. Everything is an object and most code is put in classes.
.NET tutorials
C# tutorials
VB.NET tutorials
Java
Java, designed by Sun Microsystems, was created with portability in mind. Older versions earn Java a lasting reputation of being very slow by being interpreted, though newer versions' programs are compiled "just in time" as they are being executed by the virtual machine, and get recompiled to be further optimized as they run. Furthermore, Java programs can be compiled beforehand into machine code, giving them speeds comparable to regular compiled languages, though at the cost of portability.
- Power: Medium - The Java language itself is somewhat limited, being designed to be simple to learn. It does however include an extensive library containing things that most other languages' libraries do not. However, it is still not as powerful as C++, as C++ can still do many things Java can't, such as direct access to hardware (Because of its portability). However, with the Java Native Interface Technology, or JNI, it is possible to write some C++ "glue" code so Java can access the Operating System. See Also javagaming.org.
- Portability: Extremely High - Java is initially translated into bytecode, which can then be run by any Java virtual machine, regardless of operating system. Unfortunately most people don't have the latest runtime environment and they don't all do things exactly the same (Especially the AWT, since it is native-based), but this usually isn't a problem.
- Speed: Medium - High - It isn't quite fast when interpreted, but with just-in-time compiling (JIT) Java has gained enough speed to be competitive with native languages such as C/C++. There's also a small delay when starting a Java application when the JIT compiler examines the code.
- Ease of Use: Medium - High - The syntax is somewhat similar to C++ and C#. It's a higher level programming language than C/C++ and resembles C# much more than C++ in terms of ease of use. Pointers are hidden, and it includes automatic garbage collection.
- Library Compatibilities: Medium - The Java API includes libraries to handle a huge number of graphical operations and sound, device input and networking are also present. Unfortunately, they're so huge as to be forboding, with large parts deprecated. These functions are not geared for game development however, but there's a few engines and libraries that enables large scale game development in Java. One of the popular game libraries is LWJGL, which provides a simple interface for accessing input/audio/graphics hardware though Java.
- OOP: Very High - Fully Supports OOP; everything is a class. ( aka Bondage and Discipline OO ) (exceptions are the Primitives int, long, double, char, etc; although they can be classes Integer, Double, Character, etc)
Java tutorials
KonsolScript
KonsolScript is an interpreted scripting language, developed by a college student. It was created with game programming in mind. You focus on the fun of the game development and not to the dull moment of learning the language. It is also being used as a teaching tool in a programming class.
- Power: Medium - KonsolScript is designed to be a homebrew game programming language. It is a very high level programming language where most of the required functionalities (like graphics, sound, key inputs, file access, shell execution) by a homebrew game developer have been built-in so realising a game will be much faster. Plus tile-based map is handled for Rapid Game Development.
- Portability: Medium - KonsolScript is only available for GNU/Linux and Windows users. The scripts are processed and being compressed for later interpretation of a KonsolScript engine running either of the two supported OS.
- Speed: Medium - For simple tasks, the speed is more than average. But when it comes to hardcoded game programming (using the built-in graphics functions), the performance could be slowed down to below average -- where creating a very good algorithm is very well recommended to make it faster. But KonsolScript interpreters are designed to be a scriptable game engines where tile-based maps are being handled.
- Ease of Use: Medium - The syntax is mostly similar to C. Programmer does not have to worry about memory allocation as it is already handled by KonsolScript.
- Library: No support built into language - KonsolScript is designed to be packed with functionalities needed by a game development newbie (except for network and database which are still under planning) -- thus, there is no support for external library.
- OOP: No support built into language - KonsolScript does not support OOP. But you can do so by simulating it through arrays and parameter passing. This is obviously more difficult than it should be with an OOP language but OOP in an interpreted language will cause programs to be awefully slow.
KonsolScript Tutorials
Python
Python is an interpreted language that was invented in 1990. It aims to be easy to use and to extend, which it does both quite well. It has a very clear and minimal syntax. The interpreter is open source, and already pre-installed on many Unix systems.
- Power: High - Python conveniently supports all kinds of programming styles.
- Portability: High - The Python interpreter has been ported to most major platforms. Almost all Python code will run unchanged on all of them.
- Speed: Medium - Definitely slower than a compiled language, but not slow enough that your games crawl. Python is more than good enough for 2D games, but if your game involves serious number crunching or fast 3d movements, you should implement that in C/C++ and plug it in to Python
- Ease of Use: High - Python syntax has a few odd elements, but it is very consistent and people tend to pick it up quickly. The module system is extremely convenient.
- Library Compatibilities: Medium - High - The language comes with a lot of libraries, but most of those are aimed at simple scripting and web programming. Some game programming libraries are also available though (PyGame, PGU, Pyglet, Rabbyt, PyOpenGL, Panda3D which sees use Disney's online games, Soya3D, Blender) and it is very easy to write wrappers for other C libraries or use seamless C++ library integration using Boost or C/C++ library integration using SWIG.
- OOP: High - The whole language is designed in an object-oriented way, supports polymorphism and everything.
Python tutorials
BASIC
BASIC is a language that was invented in the early 1960s and is still used today by developers for a variety of purposes, including business applications, everyday programs, and yes, games. This language not only made the turning point for all high-level languages that are used today, it became a revolution and made way for all higher-level languages like Euphoria, Visual Basic, and Pascal.
BASIC
BASIC is one of the first interpreted languages. In 1964, in Darthmouth University, the creators of the language called the BASIC language, Beginner's All-purpose Symbolic Instruction Code. Still widely used today for a multitude of purposes. Many old dialects of the language have been created, including QBASIC, blitzbasic, GWBASIC, and TrueBASIC, as well as modern basics like PureBasic and of course the ever-popular, Visual Basic. While most of the old dialects of basic are not suited to modern game development, most of the newer ones should be fine, expecially the free and open source FreeBASIC.
- Power: Low/Dialect Dependent - Few dialects of basic contain low level commands to make an impressive game, but BASIC contains several libraries to access these commands. Due to the old-fashioness of the language, the ANSI BASIC language is not modernly up-to-date with necessary features such as pointers. However in the case of PureBasic the syntax is simple but has advanced features, such as pointers, structures, procedures, dynamically linked lists etc.
- Portability: Medium/Dialect Dependent - Many dialects of BASIC such as freeBASIC contain minimal porting to the most popular operating systems, such as Windows, MAC and Linux.
- Speed: Very Low/Dialect Dependent - Very few dialects of BASIC barely manage to be up to speed compared to modern languages like C++ and .NET. There are, however, some machine-code compilers like PureBasic and XPB Compiler, whose speed can be compared to languages like C. In the case of PureBasic there are no bottlenecks like a virtual machine or a code translator. The generated code produces highly optimized executables regardless of the OS on which it is compiled. Plus you can compile programs into a 'commented asm output file', containing all code in a comprehensive asm format; all directly recompilable with FASM.
- Ease of Use: Extremely High - Most dialects of basic are very easy to learn and use. Designed to be an amateur language, the various dialects of the language are usually considered as a good starting place for game development.
- Libraries: Medium/Dialect Dependent - Many libraries out there exist to help the BASIC language, but the support for BASIC is not nearly as abundant as C++.
- OOP: None/Dialect Dependent - Very few BASICs exist to support OOP, and those very few BASICs are very unpopular.
Visual Basic 6
Visual Basic (VB) is a language sold by Microsoft. Microsoft have stopped providing support, but people still use it. It was meant to be used for GUI (Graphical User Interface) applications, which paved for the software methodology, RAD (Rapid Application Development) -- GUI designer that is very easy to use. It was such a popular language that there were a fair amount of people programming games with it. It is a descendant of the BASIC programming language and shares its syntax. This is probably not the language for a beginner because the only way to obtain it now is to buy it secondhand or use illegal means. It isn't a very advanced language and took a lot of criticism for it. The main reason people use it is because of its ease of use.
- Power: Low - Doesn't support many advanced features, especially compared to languages such as C++.
- Portability: None - It is sold by Microsoft and thus doesn't run on anything but Windows.
- Speed: Low - It is a fair amount slower than C/C++, since the compiler does only minimal optimisations. Fast enough for most purposes, but not for huge professional games.
- Ease Of Use: Very High - This is the reason people use Visual Basic. The language can be picked up much quicker than most. The Visual Basic runtime engine takes care of memory and is loosely type, meaning type-casts do not have to be explicitly defined by the programmer.
- Library Compatibilities: Medium - It doesn't have a world of libraries available to it like C/C++, but it has been around long enough that there's plenty of useful stuff floating around on the internet.
- OOP: Medium - Has some rudimentary support for OOP (Object-Oriented Programming), and lacks tons of useful features. Its objects are little more than structures that allow routines inside of them.
Visual Basic tutorials
Ruby
Ruby is an interpreted, scripting language that is similar to Python, C, and Perl in many ways. Invented in 1993, Ruby, or more properly ruby is a pure, object-oriented language used in many games today. Although most games aren't made in ruby completely, many games use ruby as a scripting langauge.
- Power: High - Ruby is very similar in power to Python. Strong features include class mixins, metaclassing, and blocks.
- Portability: High - ruby is available on all modern versions of Windows, Macs, and Unix (Linux) and other OSes.
- Speed: Low - As ruby is a interpreting langauge, it is similar in speed to python, which lacks speed.
- Ease of Use: High - ruby is very easy and simple to pick up, as most of its language is designed for newer programmers. It doesn't have a complex syntax which makes it a candidate as an easy language.
- Library Compatibilities: Medium - Many engines and libraries such as SDL have wrappers for the language.
- OOP: Very High - The entire language is based upon object-orientation. Almost everything is a class. Supports metaclassing and mixins.
wrapper:
Rubygame - www.rubygame.sourceforge.com
RubySDL - www.kmc.gr.jp/~ohai/rubysdl.en.html
Lua
Lua is a multi-paradigm, lightweight, reflective, imperative and procedural language, designed as a scripting language with extensible semantics as a primary goal. Most games aren't made in lua completely, but many use lua as the scripting language.
- Power: Medium - lua supports first class functions and coroutines, and object-oriented programming.
- Portability: Very High - lua is available nearly everywhere C is.
- Speed: Medium-high - lua is one of the fastest interpreted languages.
- Ease of Use: High - lua has a very basic syntax which is very easy to pick up.
- Library Compatibilities: Medium - lua can interact with almost every C library using tolua
- OOP: High - Although not implementing OOP the traditional way, OOP can be achieved using tables and first class functions
Conclusion
So, as I have said before, just decide what you want in a language and pick the one that best meets your needs. No language is perfect. They all have their trade-offs. Happy programming!
See also
|
|