[Though Java might initially come off as a mediocre language, Appstream CTO Gavan Woolery argues that it has advantages you might want to consider for your next project, in this #altdevblogaday-reprinted opinion piece.]
First, let's be clear: I am speaking to anyone but
console/mobile/AAA developers here.
I like to program 'close to the metal.' It gives me a feeling of control, even if the compiler is actually completely rewiring my code. I like C and C++ because they do not try to hide much from the programmer â€" they are very basic imperative languages. That said, there are many, many things I hate about them.
For a long time, Java struck me as a somewhat mediocre language. Its performance seemed a little bit weak and most people would scoff at the concept of using it for game programming.
More recent versions of the JVM actually have great performance. It can be difficult to organize an effective benchmark
, but some tests suggest that Java can actually exceed the speed of C/C++ in certain cases. This is due in part to the fact that Java has more constraints in some areas (i.e. pointers), and that it can be optimized more effectively based on this.
Java can also optimize itself with JIT compilation, and optimize between successive runs. That said, you definitely should not
choose Java on the basis of performance alone.
I once heard something that has stuck in my mind ever since: "servers are cheap, programmers are expensive." In other words, you have to carefully choose your battles: at what point is optimization worth a programmer's sanity? Java might not be the fastest language, but it will keep you slightly more sane than C/C++, and is usually worth the slight performance penalty.
But what is really important is that the loss of performance can be a good
thing. When you stop focusing on performance, and start focusing more on your game, a new world of opportunity opens up.
I hate to always bring it up in examples, but take a look at Minecraft
: simple graphics, but it runs on a variety of hardware and operating systems. Java programs have better potential for a long lifespan â€" this might not seem too important, but try launching an old DOS game these days â€" can be quite tricky sometimes, even with an emulator.
Java is also cross-platform â€" this makes porting really painless. You can also run Java in the browser as an applet or via a quick-launcher. Managing 'imports' and 'packages' is much easier than dealing with '#include' statements in large projects.
You can also easily get a free IDE up and running quickly: Eclipse (for C/C++, last I checked, setting up the compiler could be tricky on Windows, which does not include a compiler by default like gcc on Mac/Linux). C# actually is quite good in many ways as well, but unfortunately its open source counterpart (Mono) leaves it trailing a little bit behind on operating systems other than Windows.
Clojure is another language you might want to examine. It is a relatively new functional language that compiles to the JVM, and is a LISP dialect. It imposes certain restrictions (i.e. state-based immutable data) to make multithreading as simple and painless as possible. As the number of cores on a CPU increase, I could see Clojure being a real contender, although I am still slightly skeptical of its performance in some areas.
TL;DR: sacrificing performance can be a hard pill to swallow â€" but it is also very liberating to not worry about it so much and focus on making something simple and easy to code.
[This piece was reprinted from #AltDevBlogADay, a shared blog initiative started by @mike_acton devoted to giving game developers of all disciplines a place to motivate each other to write regularly about their personal game development passions.]