One in two Pythonistas should learn Golang now
By: Rhea Moutafis
Tags: Python, Golang, Software Development, Towards Data Science, Programming Languages

Your average software engineer is still in love with Python. Married, even.

But not those at Google, Uber, Dropbox, Soundcloud, Slack, and Medium. The programmers at top corporations have long fallen for the language with the cute mascot.

That’s not to say that Python is no good. It’s great!

But whether it’s for APIs, web services, or data processing — while most developers are still using Python, top-performers are adopting Golang, or Go, more and more. Because it rocks.

Created by pioneers

Go was invented by an all-star trio at Google: Robert Griesemer was one of the heads behind Google’s V8 JavaScript machine and a main developer for Sawzall, another language invented by Google. Rob Pike co-developed the Unix environment and co-created the Limbo programming language. With Ken Thompson, the team had the inventor of Unix and the creator of the B language — the predecessor of C — on board.

Google was originally written in Python — yes, Python is still cool — but around 2007, engineers were searching for a better language to perform typical tasks at Google. They were encountering problems like these, according to a talk by Rob Pike in 2012:

Slow builds: Producing new code was taking forever. Sounds familiar to me!

Producing new code was taking forever. Sounds familiar to me! Uncontrolled dependencies: Have you ever tried to install a software package, only to find out that you have to install at least five other dependencies and umpteen sub-dependencies to get it work? It turns out that even Googlers have that problem.

Have you ever tried to install a software package, only to find out that you have to install at least five other dependencies and umpteen sub-dependencies to get it work? It turns out that even Googlers have that problem. Each programmer using a different subset of the language: In Python, one developer might use the numpy package, another one prefers scipy, and so on. When the programmers want to blend their code into one package, things get messy.

In Python, one developer might use the numpy package, another one prefers scipy, and so on. When the programmers want to blend their code into one package, things get messy. Poor program understanding: People who say they understand code in the minute they read it are lying. At least if it’s not a dead-simple “Hello World”-program. And the documentation of the code often doesn’t help — in most cases it doesn’t even exist, or it’s badly written.

People who say they understand code in the minute they read it are lying. At least if it’s not a dead-simple “Hello World”-program. And the documentation of the code often doesn’t help — in most cases it doesn’t even exist, or it’s badly written. Duplication of effort: Have you ever copied a piece of code from one part of the program, just to copy it somewhere else? Bad practice. But most programming languages make it easy to do.

Have you ever copied a piece of code from one part of the program, just to copy it somewhere else? Bad practice. But most programming languages make it easy to do. Cost of updates: With such a mess as described above, does it really surprise you that updating your software is going to take a lot of time and brainpower? Not cool.

With such a mess as described above, does it really surprise you that updating your software is going to take a lot of time and brainpower? Not cool. Version skew: With duplicate code floating around the place, engineers might only update one version of the original code snippet and forget about the others. So you end up with a version that contains both new and old code. Sounds chaotic? It is.

With duplicate code floating around the place, engineers might only update one version of the original code snippet and forget about the others. So you end up with a version that contains both new and old code. Sounds chaotic? It is. Difficulty of writing automatic tools: It’s possible to write programs that write code themselves — in fact, most programs do that at some stage. But with modern programming languages, that is still hard to pull off.

It’s possible to write programs that write code themselves — in fact, most programs do that at some stage. But with modern programming languages, that is still hard to pull off. Cross-language builds: You know the problem — Python is great for small-to-medium scripts, C++ is great for elaborate programs, Java is great for web development, Haskell is great for lazy but robust code. The result is that a single program often contains snippets from many different languages. But for compiling, debugging and the sake of cleanliness, it is much better to write a program in one single language.

So the trio set out to design a language that was clean, simple, and readable. A language that would eliminate, or at least ease, these all-too-common problems in software engineering.

A lean language…

The root of many of these common problems is the complexity of modern languages. Think of Python or C — have you ever tried to read the whole documentation? Good luck with that.

In contrast, the greatest feature of Go is its simplicity. That’s doesn’t mean you can’t build complicated code with it. But Go is very deliberate about not having features that bring more complexity without solving the problem.

For example, Go doesn’t have classes like other object-oriented languages. A much-used feature of other languages, classes are great to make one object inherit the properties of another object. The problem is that if you try to change the structure of one object without changing that of the others, you’ll break the code. Go has an alternative, called struct, that favors composition over inheritance.

The gopher for the Google App engine. Image from the Golang website.

Other key features of Go are:

Type safety: In C, you can use pointers to do just about anything — including crashing the program. Go doesn’t let you mess around like that.

In C, you can use pointers to do just about anything — including crashing the program. Go doesn’t let you mess around like that. Readability: Like Python, Go puts readability first. This makes it more beginner-friendly than most languages, and makes code easier to maintain.

Like Python, Go puts readability first. This makes it more beginner-friendly than most languages, and makes code easier to maintain. Documentation: Especially junior developers find it tedious to write some blurb about your code so that others can use it. With Godoc, this process is much more automatized than in most languages — and the developers don’t have to waste valuable time by writing down what they’ve been doing.

Especially junior developers find it tedious to write some blurb about your code so that others can use it. With Godoc, this process is much more automatized than in most languages — and the developers don’t have to waste valuable time by writing down what they’ve been doing. Orthogonality: This means that if you change one object in your code, no other object will change because of that. In this sense, a radio is orthogonal because the volume doesn’t change if you change the station. Much unlike C, for example — if you change one thing, then others can depend on that and also change. Go is orthogonal because it makes things simpler.

This means that if you change one object in your code, no other object will change because of that. In this sense, a radio is orthogonal because the volume doesn’t change if you change the station. Much unlike C, for example — if you change one thing, then others can depend on that and also change. Go is orthogonal because it makes things simpler. Minimality: In Go, there’s only one way to write a piece of code. Compare that to Python, where you have zillions of ways to write one thing!

In Go, there’s only one way to write a piece of code. Compare that to Python, where you have zillions of ways to write one thing! Practicality: Important stuff should be easy to code — even if that means that other things are impossible to do in Go. The logic here is that you want to increase the productivity of a developer by making recurring tasks fast and easy. And if there is a more complex problem — which is a rare occurence anyway — they can always write that in another language.

All this might sound boring and uncreative. And in a sense that’s true — this is no language with funky features that you could use to impress others, plethora of ways to solve a problem, no freedom without limits. Go is no language that is there to explore, to do research with.

But it’s amazing when you’re trying to build something that works. When you’re on a team with lots of different people from different backgrounds working on the same code. When you’re tired of all of the mess that you encounter with other languages.