Discover the pros and cons of Go for DevOps
With uses in container systems, API integration, and microservices, Go — sometimes referred to as Golang — is an increasingly popular programming language for DevOps and cloud projects.
Go is a strongly typed open source language that has recently class in the IEEE’s 10 Trending Programming Languages for 2022. Because Docker and Kubernetes are written in Go – as are widely used DevOps tools like Terraform and Red Hat OpenShift – learning Go opens the door to writing software. implementations and custom plugins and contributing to these open source projects.
“Go itself is increasingly becoming the language of the web, the cloud, and cloud environments,” said Teiva Harsanyi, senior software engineer at Docker and author of the book. 100 GB mistakes and how to avoid them. “Most of today’s systems in the context of cloud environments are built in Go.”
Harsanyi started working with Go six years ago, when his team was tasked with migrating a large, monolithic application written in C++ that he called “a little messy.” When the organization wanted to modernize the project by making it more granular and reliable, Go was a natural choice.
In his book, Harsanyi addresses the top mistakes he sees among Go developers and shares tips for getting the most out of the language. The book’s 12 chapters walk the reader through common Go errors by category – such as data types, strings, and optimization – with sample code to illustrate the problems and their solutions.
Benefits of the Go Programming Language
Despite Harsanyi’s 100 Ways Go Developers Can Go Wrong in the book, he is an advocate for the language. Go, created at Google in 2007, lags behind more established options like Python and Java in popularity, but Harsanyi believes it has several advantages, including stability, simplicity, and speed.
According to Harsanyi, the Go landscape hasn’t changed much in the three years since he started writing his book, which he described as one of the advantages of the language. Harsanyi said the introduction of generics in March 2022 was the first major addition to Go he’s seen since he started working with the language.
These relatively infrequent updates, combined with the expressive nature of Go, make the language stable and readable. Newcomers to modern software development projects are often greeted with hundreds or thousands of lines of existing code. With Go, “it’s very easy for someone to come on a project and figure out what the code does,” Harsanyi said. This shallow learning curve is an advantage in fast-paced DevOps environments that require concise and maintainable codebases.
Go’s readability largely stems from its simple syntax and standardized design. Since languages such as Python and Java provide multiple ways to accomplish the same task, different programmers may use various methods to achieve the same goal. While this wide range of choices is appealing to some, others find it overwhelming, especially when adopting external libraries and frameworks leads to more complex projects with many dependencies.
Go, on the other hand, relies heavily on built-in standard libraries, which means Go programmers are less likely to need to learn a different approach when joining a new team. Harsanyi gave the example of implementing a new HTTP service. While Python developers can choose from dozens of libraries and frameworks, Go has a library of standard HTTP services as part of the core language.
Because Go is statically typed and compiles directly to machine code, Go programs tend to be fast and lightweight, supporting rapid deployment and the high performance needs of DevOps workflows. Harsanyi has worked with a variety of languages - including Java, Scala, Rust, and Python – and finds Go to be most effective for back-end applications.
“I had to go back to Java last month, and it’s an ecosystem that’s so [more] difficult to understand, he says. There are libraries everywhere. … So I see more and more back-end developers choosing Go in the future.”
Pitfalls for developers using Go
One of the biggest missteps Harsanyi sees among Go developers involves concurrency: a programming approach intended to improve performance by executing multiple operations at once. This feature is beneficial for DevOps engineers who need to run independent processes and functions concurrently.
While some languages, such as Rust, require external libraries to write concurrent programs, Go includes concurrency primitives called goroutines and channels as part of the language. However, implementing concurrency correctly remains a challenge for Go developers. study 2019 by researchers at Pennsylvania State University and Purdue University.
In explaining this discovery, and throughout the book, Harsanyi said that Go’s simplicity did not eliminate the need to build a deep understanding of how the language works. “Simple doesn’t necessarily mean easy,” he said. “You may have something simple to write as part of the language, but that doesn’t necessarily mean it will be easy to implement.”
Developers should also consider how different programming languages can work together, rather than seeing them as competitors, Harsanyi said. He sees Go and Rust as particularly complementary for DevOps engineers: Go for implementing fast, efficient, and reliable cloud applications, and Rust for low-latency systems where performance is crucial.
“As a back-end engineer, I see both languages as really the future,” Harsanyi said. “I really like that the two languages don’t seem to conflict with each other.”
Download PDF to read an excerpt from chapter 3 of 100 GB mistakes and how to avoid them. Chapter 3 (“Data Types”) covers common mistakes related to data types, slices, maps, and comparing values in Go. The book, released August 2022, ISBN 9781617299599is available from Manning.