
Let me explain the title of this article.
1. Both Python and Go are excellent programming languages, each excelling in different areas. Python is more mature, has a wealth of libraries, and is suitable for scripting and data analysis, dominating the field of artificial intelligence. Go, being relatively young, is more vibrant and excels in concurrent programming and high-availability scenarios.
2. Geek Time currently uses Go to build backend services, while Python will be adopted in the future for data analysis.
3. The author of this article is Jake Wilson, the current technical manager of the SketchUp web team. He has worked at Boxuno.com, Monolla.com, Google, and other companies. At Google, he participated in projects such as Google+, Chrome, and Webmaster Tools.
Why explain all this? Because I’m not tough enough.
——————
Go was born at Google, created by three legendary figures in the computer field: Rob Pike, Ken Thompson, and Robert Griesemer. Due to its prestigious origins, Go attracted a large number of developers’ attention from the very beginning. In the ten years since its inception, many applications based on Go have emerged. Not long ago, Zhihu also abandoned Python.
Former Google employee Jake Wilson believes that compared to the familiar Python, Go has many excellent features and can often replace Python. He has already used Go to replace Python in many tasks. So what unique charm does Go have? What advantages does it have over Python? Let’s find out together.
The Most Desired Programming Languages for Programmers in 2019
The Prestigious Go Language
For a language that is only ten years old, Go has developed remarkably quickly. Docker, a leader in the container world, is written in Go, and many teams in China widely use Go. Recently, HackerRank conducted a programmer skills survey that involved over 70,000 developers from more than 100 countries. The results showed that in 2019, the top three programming languages programmers wanted to learn were Go, Kotlin, and Python, with Go ranking first at 37.2%.
However, it is undoubtedly challenging for Go to shake the long-standing position of Java, which has been dominant for over twenty years. According to HackerRank data, in 2018, Java still ranked second in the list of the most popular programming languages among developers, Python ranked fourth, and Go ranked thirteenth, still a considerable distance from the first place, JavaScript.
But for the author of this article, Jack Wilson, although Go is still “young,” it already possesses many excellent features.
What Makes Go Language Good?
I have already replaced Python with Go for many tasks; here are a few examples:
-
Processing cloud logs stored on S3
-
Moving TB-sized files between buckets and/or regions on S3
-
Matching local database records with files on S3 to ensure file synchronization
These tasks are mostly one-time operations, so using a scripting language is more appropriate. These tasks require quick programming, and the code is generally discarded after one use. Generally speaking, the demand for such tasks is quite novel and specific, and the code rarely needs to be reused.
Now, let me explain why Go can replace Python for such tasks.
Convenience of Having a Compiler
I often make very basic mistakes when writing Python. I might misname variables or functions or pass incorrect parameters to them. Such errors can be partially detected by debugging tools, but these tools usually require specific setup. I have never configured pylint conveniently, and I dislike using heavy IDEs that are more troublesome to set up.
The worst-case scenario is that you might accidentally misspell a variable name, and this error can be hard to detect. Your script might run for several hours before encountering this error, and then everything crashes, forcing you to start the script all over again.
Most of these errors can be caught by unit tests, but unit tests rarely cover 100% of the code, and I don’t want to waste time writing unit tests for a script that is only used once.
A language with a compiler can solve all these problems. The compiler can detect all the basic errors you make. For this reason, when writing code that spans hundreds of lines, I prefer to use languages like Go.
Development Speed
However, one downside of compiled languages is that your development speed generally decreases. This is particularly evident in languages like C/C++ and Java. However, Go is a very simple language, and I find that its development speed is not significantly slowed down. Don’t get me wrong; I don’t mean to say it’s faster than Python, but rather that using Go is not much slower than Python, generally achieving about 85% of the development speed of Python.
Considering the basic errors that can be avoided with a compiler, I think sacrificing 15% of development speed is worth it.
Better Concurrency
You may already know that Go was designed for concurrency.
In my team, we often need parallel programs because we have to operate on a large amount of data in our database on S3.
If the task is I/O intensive (and many tasks are), we can easily deploy Python threads. But if the task is CPU intensive, using Python becomes inconvenient due to the global interpreter lock.
I really enjoy the ease of running simple code in Go without modification in a multithreaded manner. Have you ever encountered this issue in Python: multithreaded code that you copied and pasted doesn’t work at all? This problem does not occur in Go.
Simple Deployment
I prefer to package all dependencies into a single binary file. I often run my scripts on EC2 servers to make the environment closer to our servers on S3. If I were using Python, I would need to ensure that all required packages are installed on the server, and my colleagues cannot install any packages that might cause conflicts.
Virtual environments can solve most problems, but I still find using Go more convenient.
I usually cross-compile my code on Mac and Linux, copy it to the remote server, and then let it run. All the dependencies my code needs are in a single binary file.
Consistent Style
Initially, Go’s formatting tool, gofmt, drove me crazy, especially its requirement to use tabs instead of spaces for indentation. I thought it was insane.
However, after using it for a while, I began to appreciate it. When writing code, I can be creative with formatting, and the formatting tool takes care of everything. My code style is consistent, even when writing different projects. This is because formatting is a feature of the standard Go tools.
But if I want to achieve this in Python, it would take some effort. I would need to configure the pylint tool correctly and ensure it is used in every project.
More Convenient Tools
Gofmt is just one small example among many tools in Go. All the editors I like to use—VSCode, vim, and Sublime Text—have corresponding extensions for Go, allowing me to easily enjoy the benefits of Go tools.
This way, I can have the intelligent experience of writing Java without actually using an IDE. I have never had this experience while using Python.
Go Language Also Has Its Drawbacks
Whenever I see articles criticizing Go, they almost always mention the lack of key features, such as generics. I believe that the absence of generics is not a big deal—you’ll find that using maps and slices can achieve many surprising operations. However, I have encountered many other issues while using Go.
Lack of Flexibility
First of all, Go may be the most “stubborn” language I have ever used. For example, it forces you to use tabs instead of spaces for indentation (assuming you use the gofmt tool), forces you to use a specific file organization structure, and forces you to program in the GOPATH environment variable, among other things. This language has too many features that are difficult to change.
One reason Go is simple and easy to learn is that you cannot change these features. If you are unwilling to export all capitalized variable names, then sorry. Fortunately, these features of Go do not violate my principles, but I can understand if someone finds some of these requirements unreasonable.
In contrast, Python is much more flexible.
Poor Library Support
Comparing Go and Python in this regard is somewhat unfair. Go appeared much later than Python, but I still find it puzzling when I discover that some features are not supported in Go. I have even found many code snippets on StackOverflow that should have been built-in features, and everyone needs these features, copying and pasting the code into their projects. Shouldn’t these features be embedded in the language?
Speaking of which, I think of two examples from recent years:
-
Sorting slices (fortunately, this has become much easier in Go 1.8)
-
Math.round only supports integers and cannot round floating-point numbers (for example, if you want to find the nearest integer to 0.5, Go cannot do it). In fact, there was no math.round function before Go 1.10.
Of course, some of these issues are due to the lack of generics in Go, and others are because the developers of Go only add the most necessary features to Go’s standard library.
I understand both points, but I still feel frustrated when I encounter small problems that require me to write code to solve.
I hope that as Go continues to develop, its issues will become fewer.
How to Learn Go Language?
As a lightweight open-source language, getting started with Go is not difficult. I would like to recommend the Geek Time column “Core 36 Lectures on Go Language” by Hao Lin, who is well-known in the Go ecosystem, or has read his book “Go Concurrency in Practice.” He is the founder of the GoHackers technical community and the former head of big data at Qingsongchou.
This column currently has over 20,000 subscribers learning.
The column was initially planned for 36 lectures, but it exceeded expectations and ended up with 50 lectures, and has undergone repeated iterations and refinements, with all illustrations redrawn. After negotiating with the author, the price will be adjusted to 99 yuan. Today is the last day before the price increase; I have opened a group for 1,000 people, and the subscription is currently only 58 yuan, with only a few hundred spots left. If you’re interested, you can take this opportunity to join and learn together.

Click the original text to join the group directly
