Sunday, 3 February 2008

Why Java?

For a long time we've been harranged as to why we're using Java to develop Moviestorm. Java is a programming language that our dev team writes in all day long. So twak spends all his day looking at something like this (highlighted stuff is Java itself):

The games industry standard is to code in C++. Most people in the team know C++, but Moviestorm doesn't use it. The main reason is speed of development. Java has a lot of features, libraries and tools that helped get us started as a startup very quickly, and we like it that way. There are a huge range of BSD-licensed libraries available, many great free tools, the build times are low (a clean build takes 30sec, compared to 30min for comparable projects in C++). It is also portable, Dave gave us a working Mac port in ~6 days.

The rest of this post turned into a myth-busting exercise so it probably best done as a Q&A.

Q) Isn't java slow?
A) No, it's now accepted that it is as fast as C++. Because it compiles to bytecode rather than native binaries it adapts itself to whatever processor you happen to have on your computer. There are faster ways to code, such as optimized C or assembler, but those eat up so much developer time (writing, maintaining and porting to other platforms) that we only resort to them when we need real speed. And yes, sad tho it is, companies sacrifice developer time their end for performance on your end every day. There are also a bunch of high level tricks, such as run time code generation that help us crank up the speed.

Q) Doesn't Java need to be installed before it can be used?
A) Yes, but Moviestorm installs it for you. In the old days you had to install it yourself, but that's all changed. Any version of the Java runtime that Moviestorm adds, is removed when you uninstall. This is no different to the way you need to install Microsoft the .NET runtime for some applications (except it doesn't uninstall unless you tell it to).

Q) I don't like Java because I keep getting javascript errors on webpages.
A) Java isn't javascript (ECMA) . And Javascript isn't even that bad, it's just that it's one of the more complicated parts of web pages and so the most likely to go wrong.

Q) I read somewhere that the Java language sucks, and is harmful to students to learn it.
A) Yes, I agree, it's a balls up of a language. It is a system designed by geniuses to be used by monkeys; a collection of constructs to make people right "correct" code according to someone else's definition of correct. When you're a programmer you want maximum expressiveness, rather than someone else's definition of correctness. But its better than C++ (which started out as a mere pre-processor to C). We use Java because of the ecosystem around it rather than the language itself. I'd would like to go functional, but those languages don't have the tools and libraries yet.

Q) I hate Java because of the NullPointerExceptions.
A) Moviestorm users sometimes see these when they don't have the correct addon pack or similar. It means that the programmers have forgotten to initialize something, somewhere, sometime. If it was a C++ the program would (with the same absence of defensive coding) have probably been stopped by the operating system. Because this isn't the case these errors are less serious and we get to spend more of our time fixing more show-stopping bugs (such as getting Storm to run on bizzare ATI hardware)

While we'll admit that Java has it's share of flaws, but for now it is the sweet spot of game development for a startup!


Overman said...

Well stated. I'm convinced. :)

Ricky Grove said...

Fascinating post. Now, I know the basic concept of Java as a programming language, but can you show how it actually works in Moviestorm? Perhaps a bit of code and then indicate what it does? I'm just curious. Always been interested in programming, but it's intimidating.

twak said...

@Ricky -
I was considering a screen cast of a typical bug hunt as a follow-up blog post (and hopefully I'll get other departments to do the same). Maybe this week, maybe next!

Ricky Grove said...

That would be a great idea. Good luck in putting it together. I'd love to understand more about Java and how you use it in Moviestorm.

Anthony Bailey said...

Care to discuss whatever kinds of automated testing you do?

twak said...

We've had one post on testing before, but the main point is that it is really hard to unit test a graphical application. We have jUnit tests for some of our more complex data structures tho.

pbsl said...
This comment has been removed by a blog administrator.