Outside of the London’s financial district, Cambridge remains the UK’s foremost location for high tech companies. A vast number of startups and major international companies have been founded here and/or are being founded here as we speak, and big names are opening new Cambridge offices. In recent times we’ve seen more than a few turning to Go (Golang) for new projects; why would that be?

What is Go?

Go is an interesting language. Created at Google in 2007 for use in their own private “clouds”, its co-creators include luminaries such as Rob Pike and Ken Thompson. Fun facts: as well his (and their) collective work on Plan 9, famous in its own right, Ken Thomson worked with Dennis Ritchie (the R in the seminal K&R C) and the pair created Unix. Ken was instrumental in the creation of BSD, created C’s predecessor (B), and also defined UTF-8, the de facto standard format for text storage and transmission on the internet today. It’s safe to say Go’s creators know a thing or two about computing.

At the time Google were using a wide range of languages, and Go was intended to take positives from each without taking on the negatives. In particular, to quickly write code for the cloud that runs quickly, or at least quickly enough. The creators felt that existing languages in common use did not fulfil both of these criteria. They also wanted the language to be enjoyable for them to work with.

Go arrived to not much fanfare in the commercial world, but its following has been steadily growing. It is currently in the top 20 languages in the TIOBE index of most searched-for languages, and is among the fastest growing top 10 languages on GitHub at time of writing.

We see this frequently: new programming languages take some time to gain a level of acceptance and have to overcome a level of inertia as well as concerns about future (and commercial) viability. This always takes years, and a decade between conception and popularity isn’t uncommon. Most languages don’t make it, commercially or otherwise. It helps of course if at least some staff at one of the world’s biggest software companies use a language daily, but even so, Go could have remained a Google-only language.

For coders who aren’t familiar with it: it could be said to read a little like C, looked at through a lens of modernity. Its syntax is brief and clear and with little ceremony. It sheds a lot of syntactic peculiarities which were originally in C for pragmatic reasons, to make the parser easier to write, and which survived for many decades to preserve backwards compatibility; for example, Go sports a more (if not completely) consistent syntax ordering for declarations versus C’s hopscotch approach. Most newer C-like languages share these kinds of traits.

What Features Does Go Have?

Go is statically typed, like C, C++, C#, Java, Kotlin et al but unlike Python; this just means you have to know what kind of thing you have before you start doing things to it, and tends to have positive implications for refactoring and bug hunting in large code bases.

Go is garbage collected, like Java, C#, Kotlin and Python but unlike C and C++, meaning you don’t have to worry about the ceremony and bean counting involved in managing your applications’ memory usage, but in exchange you usually cede exacting control over that memory usage.

Go is “pass by value” by default, like C++ and C (and unlike C#, Java and Python), so data is copied rather than implicit references being taken to existing data. (It’s still possible to take references rather than copies.) This has potential positives for concurrency, since it means less points of contention where two parts of the program are trying to read or modify the same data, but there are time and space trade-offs. This is choice is comparatively rare for a garbage collected language.

Go is a compiled language, like C++ and C, meaning that its code is turned into optimised ready-to-run executable code by the programmer and can run without the aid of another program or framework. This is unlike Python, which in most incarnations is interpreted (translated into machine code on the fly, a la an interpreter at the United Nations) and unlike C#, Kotlin and Java which are JIT “just in time” compiled (translated right before the United Nations meeting, whilst the delegates are having coffee).

Any new language has to have sensible support for concurrency to gain acceptance, and Go has a pretty unique approach. A layer of abstraction called goroutines (a play on “coroutines”, another word for continuations, those being tasks the machine can complete partially and then defer until later, even if “later” is microseconds from now) are used atop a small number of native operating system threads. Many more goroutines can start, stop and be running at one time than would normally be wise with threads. Goroutines and their partner abstraction in Go, channels, mean the programmer does not have to manage parallel execution by hand nor use synchronisation primitives (locks around shared resources) for communication. Instead goroutines send requests down notional pipelines and receive responses (or not) later, ideally without stalling.

Like C#, Java, Kotlin, C++ and Python, and unlike C, Go supports object-orientation. As in Python, it’s optional. Go’s designers have deliberately cherry-picked which parts of handed-down-by-Moses OO the language supports, so there is no inheritance (make me a new kind of thing, just like this other one with the following differences) but there are methods (functions which “belong” to and modify specific notional objects), there is abstraction (allowing code to deal with simpler artificial views of things rather than having to appreciate every piece of code in its intricate detail), encapsulation (some data and functions are private and hidden, others for public consumption) and polymorphism (treat objects like they’re one thing, and don’t worry if they’re really something else).

Along with Goroutines, one of Go’s most beloved (or disliked) features is duck typing. Duck typing was well known in computing before Go, and means roughly “if it looks like a duck, and it quacks like a duck, then we may as well treat it like a duck; whether it is a duck or not is a philosophical question we don’t really care about.” In most languages, there is a formal declaration of APIs and interfaces which establishes the contract between two parts of the software; components will then implement specific named interfaces. In those languages, the interface has to be set in stone (in real world time) before anything can implement it. In Go, the interfaces are still formally defined in the same way, but this can be done long after the fact, after a module has long since been finished and locked down. Any part of the software which just happens to implement the interface is treated as if it has declared its compliance, and has always been that way, without requiring any changes.

One thing Go quite notably lacks is support for generics, though this seems now to be more a question of “how” rather than “whether” they should be supported in future. Generics (known as templates in C++, and as, well, generics, in C#, Kotlin and Java) allow the programmer to write code for all possible types of object (provided they meet any required constraints in data or behaviour) and then instantly make use of that code for a particular kind of object without writing new code. This is a powerful tool. On the other hand, C got by (and gets by) without generics for decades (though people did and do resort to macros, a different facility, to achieve the same effect) and Python doesn’t have them at all but is much more agnostic about what type things are in the first place. If a language has good built-in support, as Go does, for common data structures such as lists, dictionaries (aka maps, i.e. key-value look up tables) and sorting functions, the need for generics is arguably less immediately pressing.

What Major Libraries and Frameworks Exist For Go?

Virtually every language has standard support for file operations, basic mathematics, text manipulation and similar, as these are considered elementary. Some languages further support things like compression, cryptography, advanced mathematics and statistics, image manipulation and use of the web. Others still further provide full user interface toolkits, media playback, and so on. Go strikes very much a middle ground in terms of what is built in, but steers clear of functionality that wouldn’t be useful running on a server in the cloud.

In terms of access to libraries, it’s increasingly common for new languages to provide a mechanism to easily acquire and use “packages” of functionality created by other people without much (if any) manual effort by the programmer to find, build and include them. Go has such package management facilities, as does Python; C# originally did not, but has now had for some years; C and C++ largely do not, at least in terms of common practice.

There are numerous common and well supported packages for Go, particularly around the web and the cloud, where most Go code is focused. Cloud vendors such as AWS and Azure offer their own Go toolkits, and Google offer Go Cloud which aims to be a portable alternative.

Who Is Using Go?

A surprising number of companies are now making use of Go. As well as Google, there are at least some projects written in Go at: Canonical, CloudFlare, Docker, Dropbox, Facebook, Gitlab, Medium, Mozilla, Sendgrid, Twitch and Uber. And there are many more companies doing the same. Of course that’s equally true of many other viable languages in use today.

Why Are People Using Go?

Go strikes an interesting balance of features, style and performance. It is faster than Python (broadly comparable with C#, though this is hotly debated) and easier to refactor; arguably faster to write, and more modern, than C or C++; it has good libraries and community support, especially given it is a newer language than many of its peers in terms of popularity.

Amongst very demanding, highly concurrent, high availability SLA cloud applications, Go is developing a reputation for being a good choice (albeit one of a number of potentially good choices). Some reports by people who have used it in this respect have emphasised that this isn’t an automatic win, but something which still requires a good deal of engineering thought and effort, as one would imagine.

Go is by no means unique in its suitability for cloud applications, but it does present a viable option. Choice of programming language is a subjective and many-faceted decision, but it’s fair to say that Go has succeeded in proving itself to date, and that it’s on the rise.

Do you have a different view? Whether you’re looking to hire, or looking for your next job, you’re welcome to contact ECM to discuss your perspective.