GuestNo new alerts

Why Go: A Technical Overview

- Announcements399
This is the slightly more technical version of Why Go? which I wrote a couple months ago and am not quite satisfied with, I'm probably going to rewrite it at some point to make it more useful.

Anyway. I'd like to go into deeper depth about why we decided to write Gosora in Go (Golang) and not an alternative like Node.js or the ever popular PHP. If you've never heard of PHP, then I'm in awe as it's practically omnipresent.

Firstly, performance. Go is extremely fast. Not only because it's a strongly typed lower level language, but because it's fully asynchronous. This means that the program doesn't just sit around wasting cycles while waiting for MySQL to reply after a query like PHP does.

Node.js is also asynchronous, why not choose that? Well, this comes to my second point. Go is strongly typed. This creates further opportunities for optimisation and helps catch many, many bugs. Too many to count at this point, say what you will about strong typing versus weak typing, but I've seen the benefits.

Thirdly, despite all these points, it's an extremely productive language, more so than PHP has been for me in the past, surprisingly enough. Productivity is king and it doesn't get in my way so much with assumptions about me being a moron, something I appreciate.

It also uses a small amount of memory in comparison to other languages, something I appreciate as the mere act of allocating memory and dragging large amounts of memory around (e.g. copying it) can waste an incalculable number of CPU cycles.

Fifthly, and this goes more for the other alternatives like Crystal and Python than PHP / JS, but... Go is a C Style Language. This means that I and many others can get right at home with it, in comparison to a language which treats indentation as king and it reduces the number of silly mistakes someone might make in Python.

I also don't like the idea of opening every directory in a certain directory up for any random person to probe around in, if you don't adequately guard every directory you don't want people poking around in. This is a big problem with PHP, particularly with less experienced administrators.

But most importantly, we have the freedom to do whatever we want. If we want reply by email, we can just slap on a mail-server (let's keep things like this to plugins though).

In a competitive world, you don't want certain features to be up to the whims of a host and while you could get a few benefits with VPS' rather than shared in the PHP world, it's not quite the same as just tossing down a ZIP file or similar to enable a feature which is impossible there and many aren't motivated to target VPS users as it defeats the object of using PHP.

And that's not all, that's not all at all 😲

Go is also compiled. Which seems like a drawback, until you realise that I can just hack together a script to automatically restart the server when a change happens and we'll be able to dynamically reload modules in the near future.

However. The other parts of a compiled language are phenomenal. Many issues in PHP or JavaScript which would involve testing every possible path are instantly picked up by the compiler. You're not even allowed to run your program, until you fix certain glaring problems.

This means that problems which would sit for months before a poor user stumbled on it would be instantly exposed for what they are by the compiler. The compiler is not omniscient, but it's scarily effective at finding problems in my code.

It's also the secret sauce as to how Go is so fast. It can do many optimisations in advance without delaying execution and whatnot like a JIT or interpreted system do. A JIT would be useful in some areas, but it's pretty effective without one.

That summarises why we chose Go, although there are some factors I haven't mentioned like it's splendid cross-platform support which eliminated options like Rails, Crystal, etc. and to a lesser extent, PHP as it behaves oddly on Windows in some cases, although not anywhere near enough to disqualify it.