This article was published on October 9, 2021

All Pythonistas should switch to Go… or okay, maybe just half

Why Google’s language is beating Python in web development, systems programming, and more


All Pythonistas should switch to Go… or okay, maybe just half

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.

The <3 of EU tech

The latest rumblings from the EU tech scene, a story from our wise ol' founder Boris, and some questionable AI art. It's free, every week, in your inbox. Sign up now!

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!
  • 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 to 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 programmers want to blend their code into one package, things get messy.
  • Poor program understanding: People who say they understand code 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.
  • 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.
  • 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.
  • 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.
  • 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 for 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.

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.

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.
  • Readability: 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.
  • 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.
  • 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!
  • 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 occurrence 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, a 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.

…With a thriving community

Because of its simplicity, Go is one of the most collaborative languages that exist these days. The times are over when programmers used to sit in their little cubicles and never meet others.

Now, we have StackExchange to solve all our coding problems. And we have Slack, Zoom, Google Meet, and more to stay in touch with our team. But modern languages are still tailored to the little nerd in the cubicle.

Go changes that. Despite being twenty years younger than Python, it has a vibrant community.

So it comes as no surprise that they put respect, openness, and friendliness atop their code of conduct. While other languages, like Python or C, also have comparable community statements, there is less emphasis on these basic values.

So it’s no surprise that the community plays an explicit role in the annual Go surveys — unlike in many other languages.

GOLANG
The questions regarding community and leadership, from the 2020 Go developer survey

The data speaks for itself

According to the 2020 Go survey, Google’s language is mostly used for web development, network, and systems programming. The landscape for Python looks pretty similar:

Uses of Python, from the 2020 Python developer survey.

The only striking difference is how much Python is used for data analysis and machine learning. And on these domains, other hot new languages are emerging.

Apart from that, you can see that many of Python’s usages could be replaced by Go. That includes 50% in web development, 38% in system administration and DevOps, and 19% in network programming. Even if you assume that many developers do all three of these jobs, you can safely assume that half the Pythonistas are doing things that they could do in Go.

Indeed, developers are aware of the huge potential that Go offers. According to Hackerrank, about a third of all programmers wanted to learn Go in 2020.

golang

The trend is real — and since Go is dead easy to learn, we should see a shift from Python to Go in the next few years. For most companies — especially those that are not as big and well-funded as Dropbox or Medium — rewriting all their code to Go will be too expensive. But for new projects, you should at least try it.

At the biggest companies, developers are already building their success with Go. When will you?

This article was written by Ari Joury and was originally published on Towards Data Science. You can read it here.

Get the TNW newsletter

Get the most important tech news in your inbox each week.

Also tagged with