Go vs Python

Introduction

Recently, I’ve been learning Go. Part of it being that I haven’t learned a new programming language in a good three or so years, and I usually like to try at least one new one every year. I’ve been fascinated by Go, which I’ve been working on in a minor way, for about a month now. But, I also teach (and use) Python. I’ve been asking myself about when, and why, I should use one language over the other for various tasks, and how I’ve decided to approach this.

Language Introduction

Before we can get into when I plan on using either, I wanted to describe a bit about each language first. Hopefully to help those that haven’t had experience in either language to understand the power of each.

Python

Python is a very popular dynamic language. It’s statically typed (it has specific types variables are set to and allocated with), but is dynamic (variables can be reassigned afterwards). It’s also heavily Object Oriented, but there are functional concepts present in the language. In the wild, you’ll see both Python 2.X and 3.X programs out there. Python 3 is primarily supported.

Python is used for a wide array of programming problems. It shines, especially, in the realm of Data Analysis. Packages such as NumPy, Pandas, Scikit-learn, and others, really make Python a go-to for Data Analysis. In my experience, I have to say it’s even more popular than R for analysis-like problems. There are some great web frameworks for Python too, including Django and Flask. Some “big name players” also entered into the space. Primarily Microsoft with Azure Data Studio [1] and Microsoft Machine Learning Services [2].

All’s not perfect for Python, though. Comparison operators can be confusing at times and what constitutes “truth”, variable scope can also be tricky at times, and while readable, Python can be challenging when striving for better maintainable code.

Go

Go isn’t nearly as popular as Python. Go is a statically typed, compiled language. The general specs for the language are very small [3]. Go is a fairly new language on the scene, developed around 2007. Go isn’t Object Oriented, at least not as much as Python, Java, C#, etc. and is more procedural with functional concepts [4]. There’s a lot of libraries available for Go, and it emphasizes the idea of small modular code vs monolithic code bases.

All’s not perfect for Go, though. It’s a compiled language (which is both good, and bad), and a lot of the syntax can be confusing to memorize at first. At least, it is for me. That said, it’s very easy to write maintainable code with Go, and is very performant and easy to scale.

My Motivation

I briefly went over one reason why I started learning Go in the introduction, but I didn’t go into detail. I encountered go while working through some reading on Secure Coding [5], as well as other security topics in general. Go appeared to be a very safe language, where the developer was expected to be more deliberate with their types.

Since starting my Go path, I found that this is now one of my favorite languages. Some things I like include:

  1. The Object Oriented Aspects - There’s no hierarchy, no inheritance nada. The way they handle Object Oriented Programming is very similar to that of Common Lisp, and I like that.
  2. It’s fast, very fast - I haven’t stress tested Go and Python together, but in my experience so far, the execution of Go code is near instant. It’s pretty amazing actually [6].
  3. It’s deliberate, intentional - When you declare a list, it has a size. When you declare a slice, you can give it a size and capacity. You have more control over how the memory gets allocated, and what it gets allocated to. Of course, this is more that a developer has to remember when working in the language, but it’s a very nice feature. It’s like C/C++, but less messy and less error prone.
  4. It’s strict - Along with point #3 above, Go is very strict about how it operates. You define, but don’t use a variable? Expect an error. You try to store data in a slice that doesn’t belong there? Expect an error. The majority of these errors happen at compile time, not at runtime (cough Python cough). The linter also enforces a lot of this, and provides suggestions.
  5. It’s easy to pickup - The language specifications are small, and if one really tried, you can pick up the language fairly easy. But, how to effectively use what you pick up is another story. From that standpoint, it’s a much more difficult language. To be honest, this is where I struggle since I keep relating it to languages I know.
  6. There are many libraries - The core language has less going on, but there are many libraries, including many for security and analysis [7]

Safe to say that Go will be one of my primary languages going forward. I’m also considering Rust, but may stick with just Go for now. For my personal and side projects, I will likely standardize on Go long term.

When to use Python vs Go?

I mentioned a lot of good things about both languages, and my reasons for picking Go - so you may be asking yourself, am I going to recommend Go to you? Maybe, maybe not.

I believe that Python should remain the standard for the language taught for Analytics, and early Computer Science. While Python isn’t as safe as Go, it’s still easier to work with. Especially with Jupyter Notebooks (There’s also a go Jupyter kernel [8]). For people who intend not to become programmers (thinking individuals in a wet lab who do data processing, Business students, etc.), Python is still the best. I’d also say that for general Data Analysis, Python is also better, at least for now. Pandas, SQLAlchemy, and the like are incredibly good.

Another area where I don’t think Go is a good idea is in the realm of scripting and automation. Python and Powershell are perfectly good tools for both of those.

So who and when should you use Go? I’d say if you don’t fit in the above category of either a totally fresh beginner, in Business/Analysis, or for simple Automation (Not AI). Personally, I’d like to see Go used over languages such as Python, C#, and Java for general development (web, especially). I do feel that Go has a lot of good things going for it, and I’d definitely like to see it used more in the realm of Analysis long term.

Of course, the option exists to learn both languages. This is my preferred approach. Each programming language can help bring new ideas to the table. Ideas that one may not have encountered before. These can transfer from language to language, so gaining experience on both languages, even if you settle on one, is a perfectly viable (and good), strategy.

References

David Thole

David Thole
Enterprise Data Architect, Developer, Instructor. Reads/studies a lot and enjoys all things technology

Importance of Learning

# IntroductionThis post is one of a two part series about how to learn. This part will talk about:1. Why we lose natural curiosity and ...… Continue reading

Why Programming (for everyone)?

Published on August 08, 2021

Operating system privacy, why does it matter?

Published on February 14, 2021