Go or Python: Unbiased Review 2022
Today, Python and Go are often compared because many large companies switch from the first one to the second one. For example, Stream, Bitly, SendGrid chose Go for better performance, concurrency, and an opportunity to boost developers’ productivity.
However, in some cases, it’s better to continue using Python: it’s unrivaled for machine learning and data science. In others, there’s no need to make a choice, and developers use two languages for the same project while working on various tasks.
At Surf, we use both languages and develop projects we are proud of. To choose one of them when it’s necessary, we usually explore the task, estimate resources needed to do it, and discuss the results our client expects to get. As the popularity of Go for web development grows, we decided to compare it with other languages, thus answering numerous questions we hear from the clients. Having read this article, you’ll see the main differences between Go and Python in 2022.
What is Go and when it is used: Go and Python comparison
Go, or Golang, is a statically-typed, compiled programming language. It was developed in 2007, and first presented to the public in 2009. Ken Thompson with Robert Griesemer and Rob Pike created it for Google. The company planned Go would become an alternative to C—easier to learn and understand, but the same as useful. It’s quite difficult to make releases stable and fast with C, and Go was thought to have become the language for fast releases in large-scaled projects.
Today, thousands of developers and businesses prefer Go not only to C, but to Java and Python as well. There are many tasks that can be solved with Go. Here are some of them:
- back-end development,
- real time communications,
- high load services
- microservices building,
- cloud-based services,
- network utilities,
- chats and bots development.
World-famous companies choose Go for various purposes. For example, PayPal tried the language to boost their developers’ productivity, and got amazing results: now they write, release pipelines, and test using Go and are satisfied with the choice. Twitch trusts Go and builds their high load systems, distribution, and EDGE with it. American Express uses Go for high-performance microservices development, and for payments and rewards networks.
For more than 10 years since Go was launched, many companies have tried it and got excellent results.
What is Python and when is it used: Go and Python comparison
Python is a high level dynamically typed programming language. It was developed in 1991 by a Dutch programmer, Guido van Rossu, who became BDFL (Benevolent Dictator for Life) —he oversees the further Python development process and makes final decisions when necessary. Python was conceived as a descendant of the ABC programming language, capable of handling exceptions and interacting with the Amoeba operating system.
Until recently, Python was one of the most popular and universal programming languages. There is a wide range of tasks within the scope of it’s abilities:
- web development,
- data analysis,
- machine learning,
- game development,
- creating API,
- writing chats and bots,
- VR projects.
For decades of its existence, Python has been used by many companies, from the small businesses to the tech giants. Germany’s largest asset managers, Union Investment, chose the programming language to develop MALINA, a machine learning platform for investment applications, and appreciated Python’s ecosystem features. They created modules for machine learning, interpretation, and back testing. The American Public Power Association built eReliability Tracker, a web app that helps electric utilities track performance metrics.
Python success stories are numerous.
Go vs Python: 10 criteria which matter for your business
Go offers high performance. It’s one of the reasons for companies to switch from Python, Java, and many other programming languages to Go. But what makes Go so performant?
- Better CPU utilization: means that we have no downtime, and, as a result, get higher performance.
- Multithreading: helps proceed thousands of simultaneous requests and do other parallel work extremely fast.
- Statically linked, compiled apps: start time depends only on the time the CPU reads bytes from disk to memory.
To say more about the reasons why Python is slower, it’s a dynamically typed language while Go is statically typed. In statically typed languages type checks happen only once, at compile time. And if we use some IDE (Integrated Development Environment), options that are not suitable for the type are screened out. As a result, you can save from 20% to 50% speed preferring Golang.
In addition, with Go, due to the low weight, static linking, and high efficiency, you can save a lot on AWS (or any other hosting). With Python, the situation is completely opposite: you will pay more money, because it eats up much memory, disk, and CPU.
🥎 Verdict: Go wins.
Concurrency — Python or Go?
It’s one more benefit of Golang, which has a multithreading system with goroutines. Go handles incoming requests concurrently: if one goroutine is waiting for I/O, another one can process an incoming request.
Thanks to lightweight and cheap goroutines, CPU is used more effectively, and business saves its resources.
Python doesn’t have built-in concurrency, but there is Asyncio—a library that helps speed up I/O bound software. Though, it’s not that easy to use for beginners, and it doesn’t bring as high concurrency as Go has.
GIL (Global Interpreter Lock) is one more problem of Python: it imposes various restrictions on threads and degrades performance.
🥎 Verdict: Go wins.
Python has automatic memory management. Thanks to it, developers create programs fast: they don’t need to think about low-level memory details. It can save from costly memory leaks. At the same time, Python uses an automated garbage collection that has an algorithm deallocating objects which are no longer needed.
Go has automatic memory management, too. With memory allocation and garbage collection, it’s easier to avoid lurking bugs. In addition, garbage collectors help increase security and provide better portability across operating systems and runtime verification of code.
🥎 Verdict: Draw.
Bug detection — Python or Go?
In Go, bug detection is faster and more efficient than Python offers because:
- Some bugs fly off during compilation.
- Go has excellent tools that detect problems with asynchronous code automatically. For example, Go test helps detect race conditions: it runs tests on 100 threads and analyzes memory access patterns.
- Due to the very simple syntax of the language, many bugs are easily detectable visually.
Writing tests in Go is easy. It’s enough to create a file with a test next to the project sources to check everything you need. And the easier it is to write a test, the more likely it will be written.
As Python appeared much earlier than Go, it has more libraries. Today, there are more than 137 thousand of them; also there are toolsets for data science, machine learning, and data visualization.
Go has hundreds of libraries, frameworks, and databases. Tooling is actively expanded by Go enthusiasts, and it provides an effective development process.
Both languages are open-source, so developers with relevant skills can create and share new tools for Go and Python communities.
🥎 Verdict: Python wins.
Entry threshold — Python or Go?
Skilled developers can master Go from zero in two or three weeks, and the project onboarding can take about two months due to the language’s simplicity. For business, it’s another benefit: if a developer leaves a project, the new one can start working with minimal time loss.
Python is fast to master, too. It takes skilled developers about a month to learn some basics and at least three months to start solving business tasks. Speaking of Python, the time developers need to master it depends on your project specific and the complexity of tasks that your IT specialists meet every day.
🥎 Verdict: Go wins.
Whichever language you choose, note that it isn’t a tool that will protect your services from all vulnerabilities and risks. But it has some features that help developers do it.
For example, in Go there is the checksum database, which stores checksums. It’s a fast and proven way to ensure that modules committed earlier haven’t been changed.
In Python, there are numerous practices that help developers boost security in each case. A Python Security Response Team sorts out all reported vulnerabilities and recommends countermeasures.
However, it has a wider surface for attack because:
- To run Python, you need an interpreter that executes it. So, in addition to a hole in code, there may appear a hole in the interpreter.
- Python can’t be run in docker-scratch (of course your developers may do it, but be ready to get a manually built Ubuntu). It leads to vulnerabilities in a specific OS image and its packages—and we have some more holes added to the previous point.
- Python uses dynamic libraries. It means that there is still a vector of attack on the libraries. They can be replaced without replacing the program. You can update something by chance and get an encrypted server.
Of course, we can say that Python is older than each of us, and that all the vulnerabilities have already been detected. But the Log4J developers said the same thing—and then 2 RCEs were detected.
🥎 Verdict: Go wins. At the same time, many things depend on your developers’ skills and the approaches they apply.
Commutiny — Python or Go?
Go appeared much later than Python, so it has no such deep-rooted community of developers. However, there are many Python developers (and ex Python developers) among Go enthusiasts—together they have formed a young growing community of Gophers. To make it stronger, IT specialists meet at the annual conferences to discuss the latest news and the most interesting technical solutions. For sponsors, it’s a great chance to find and hire inspired Go developers, and for the Go developers it’s an opportunity to be on the top of things.
Python developers have a large community. There are numerous forums dedicated to this programming language, where developers from all over the world share experience with each other. It helps them form and support a large knowledgebase, and it’s an advantage of the Python community over Gophers. Python developers organize conferences in different countries every year, too.
Wrapping it up, both communities are active and welcoming. And being a part of them gives developers a great experience.
🥎 Verdict: Python wins, but Golang isn’t far behind. More and more Python developers master Go and write predominantly in this programming language.
As we see, many startups and large companies have switched from Python to Go.
SendGrid, a company developing customer communication platforms for transactional and marketing email, chose Go as a primary development language instead of Python: they were looking for better solutions for their backend and needed high concurrency. Besides, they saw developers writing in Go in their free time: it meant that the language was more attractive to them. So, SendGrid decided to provide their developers with an opportunity to write in Golang at work, too, and were greatly satisfied with the results.
Stream switched from Python to Go because the second one seemed to be more attractive to them due to its high performance, and stronger ecosystem. Go helped boost developers’ productivity and make them concentrate on technical solutions, not on the language itself: it has an easy syntax and law entry threshold.
Bitly switched to Go and noticed that response time became nearly 2 times faster, CPU load reduced, and it became possible to run the same workload on fewer servers. In addition, their developers needed a few weeks to master Go and start writing in it.
However, Python stays unrivaled in specific niches: machine learning and data science. For example, Google uses Python for the functioning of artificial intelligence (AI), machine learning (ML), and robotics projects.
“Python has been an important part of Google since the beginning and remains so as the system grows and evolves. Today numerous Google engineers utilize Python, and we’re searching for more people having the skills of this language.”Peter Norvig, the director of research at Google Inc.
Netflix uses Python to support machine learning potential that scrutinizes movies, pulls out images to exhibit thumbnails, and enhances streaming. The language is also chosen for all Big Data services and ETL (extract, transform, load) execution.
🥎 Verdict: Both Go and Python are chosen in many niches. For businesses, Go is a universal programming language, while Python is preferable for ML.
Developers cost — Python or Go?
According to Stack Overflow Survey, Go developers’ salaries are higher. In the USA, it’s about $140,000, while Python developers have up to $120,000. Globally, it’s about $74,000 for Go developers and $59,000 for Python developers.
There are many tasks that can be solved with Go and Python, or both of them at the same time. But Go development is more expensive than Python development because it gives large businesses stronger results. Thanks to better performance, clean and stable code, concurrency, fast code optimization, and CPU and memory resources effective usage, Go helps make operations easier and releases faster. In addition, it is a young language, so skilled developers aren’t easy to find.
Of course, there are exceptions, and choosing a programming language, you should note specific features of your project.
🥎 Verdict: Python wins, but Go gives more stable releases. With its characteristics, the language is a better match for large-scale projects.
Go and Python: comparison results in a table
To sum up
- Go has numerous advantages over Python: higher performance, better concurrency, and effective resource utilization.
- Python’s advantages over Go are a wide range of tools, lower development costs (only if you aren’t planning to use the result for decades), and a deep-rooted community.
- Go is a perfect match for web development, cloud-based services, microservices building, etc, but it’s a bad choice for machine learning and data science.
- Python is a universal language; it is often used in machine learning and data science.
- Comparing Go and Python for your project, you should pay attention to its specifics: what challenges your developers will meet and what characteristics of the programming languages are the most important in your case.
At Surf we have been developing various IT projects since 2011. Our team works with startups and large scale businesses to help them grow, having the most up-to-date tech stack to attract and retain users. With the cross-industrial experience and trend-oriented approach, our developers know everything about the programming languages to choose for any task.