Golang vs Python in Five Minutes
2 min readMay 28, 2020
In this entry, I attempt to answer one simple question: how can I quickly determine which programming language is better for my application: Python or Go? To answer that, we’ll take a high-level wholistic approach to assess how these two languages stack against each other.
Performance:
This is a tricky one because the languages are optimized to perform better or worse for different problems. For in-depth benchmarking numbers, this article does a great job: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/go-python3.html
In a few words, thanks to its out-of-the-box coroutine API, for most “parallelizable” tasks, Go is the clear winner.
Compilation:
- Golang: compiled. One interesting feature is that compilation errors are returned when dead code (i.e. non-reachable) is present.
- Python: interpreted. Errors surface late at runtime. This is one of the worst aspects of Python in my opinion because some fatal errors may only surface in production. I saw this happen way more often than I can remember. However, to be fair, there are some libraries that address this but didn’t use them extensively to comment on their usefulness.
Deployment:
- Golang: a single binary is produced. This means that you can take your binary and run it anywhere and expect the same behavior.
- Python: dependencies need to be downloaded. This makes the artifacts light in size but adds the overhead of ensuring dependencies are configured correctly.
Concurrency:
- Golang: built-in.
- Python: add-on.
Memory Management:
- Golang: built-in.
- Python: add-on.
Typing:
- Golang: static.
- Python: dynamic to the point that it is not that useful.
Third-Party Integrations:
- Golang: integrations with popular cloud services are not widely available. Typically, you will need to write your own integrations.
- Python: statistically speaking, almost every popular service in the cloud has a Python library.
Community:
- Golang: first release was in 2009.
- Python: first release was in 1991.
Domain/Usage:
- Golang: distributed systems.
- Python: data intensive applications & data analysis. It is particularly good for prototyping especially when used in a notebook.
Programming Paradigm:
- Golang: procedural. Mild support for functional programming (FP) and object-oriented programming (OOP) concepts. There is no concept of a `class` however.
- Python: procedural with good support for FP and OOP concepts.
Verbosity:
- Golang: more verbose because it has fewer built-in functions. This is in fact the core philosophy of Go: simplicity with a few features and a few updates between versions. One good feature in Golang is its support for grouped imports which helps save some typing.
- Python: it has a wealth of built-in functions and relies on indentation to define code blocks (i.e. no need for brackets and semicolons). This makes code significantly more concise.
Error Handling:
- Golang: relies on return values. It has no support for exceptions.
- Python: relies heavily on exceptions that propagate throughout the call stack.
Velocity:
- Golang: relies on the programmer to build logic.
- Python: relies on built-in and third-party libraries to build logic.