Thursday, October 6, 2011

Why I decided to program the server in Java

Usually it is a good idea to program the client and the server of a distributed application in the same programming language, because it allows to share code between the two. But in my opinion Javascript is just not suitable for server programming. Sure, there are frameworks like NodeJS which allow to program server applications in Javascript, but this is really not what Javascript was designed for.

When it comes to server programming, you shouldn't take chances. A game server must be secure, because it's an exposed target for hackers. A game server must be stable, because downtimes will annoy everyone. A game server must not have bugs, because a glitch can cause irreversible damage to the gameplay and not just a mild annoyance. And a game server must require few resources, because I will be paying for the hardware. To ensure this, I want to do this in a programming language which fulfills these criteria:
  • Object-orientation
  • Static typing 
  • Runs on Windows and Linux
  • Not interpreted
  • I have prior experience with it
The languages which fulfill these criteria are  C++, C# and Java.

Out of these languages, C++ is the one I have most experienced with. I contributed a lot of C++ code to Manaserv, the new server for The Mana World, so I even used it in almost the same context. But in hindsight I consider it a bad decision to use C++ for Manaserv. Sure, it's lightning fast and allows to minimize memory usage, but it has a lot of problems. Its very slim standard library means that you need many 3rd party libraries when you want to do anything useful. And 3rd party libraries cause all kinds of problems. Licensing issues, unstable APIs, inconsistent programming styles, unsupported platforms etc.. Its pointer semantics are a source of hard to find bugs. And its lack of garbage collection means that you spend a lot of time with thinking about how to avoid memory leaks instead of solving your problem.

So it boiled down to C# vs. Java.

Anyone who has used these two language and has also experience with other programming languages will notice that these languages are very similar. Both are almost fanatically object-oriented, both compile to bytecode, both have a very comprehensive standard library and the syntax is so similar that it's faster to list the differences than what they have in common. The only two reasons for me to choose Java over C# are these:
  1. I got a tad more experience with Java
  2. I don't trust Mono to run my code on Linux as well as the .NET framework does.
While Mono supports a lot of the features of .NET, it still is far away from 100% compatibility to Microsofts reference implementation. I want to develop on Windows, but also want to keep the option open to host the server on Linux. Having to keep the limitations of Mono in mind all the time would mean less time to concentrate on the interesting problems. So I decided to use Java, because I can trust Java that code developed on Windows will work just as well on Linux or any other platform I throw it at.

No comments:

Post a Comment