In this article, I outline why I chose the Go programming language over PowerShell, Python, and JavaScript for my DevOps projects.

In the current world of IT, DevOps engineers are in high demand. A skilled DevOps engineer requires skills in delivering applications and infrastructure rapidly into a production environment. Knowledge of a coding language is a must-have skill if you wish to work in DevOps.

There are many popular languages available to choose from, including JavaScript (Node.js), PowerShell, Java, and Python, among others. A language worthy of this list is Go, which can also be referred to as Golang.

"The 'golang' moniker arose because the web site was originally golang.org. Many use the golang name, though, and it is handy as a label." – From the official Go documentation (https://go.dev/doc/faq).

We will outline the basic concepts, comparing the language to the other DevOps languages, and answering the question, "Why would we use Go and not another language?"

The Go programming language ^

Go is an open-source programming language that was created to make building easier, more reliable, and more efficient. The Go website promotes the language as follows:

  • Go is an open source programming language supported by Google
  • Easy to learn and get started with
  • Built-in concurrency and a robust standard library
  • Growing an ecosystem of partners, communities, and tools

Go boasts a number of large companies using the language, including PayPal, Cloudflare, Facebook, Netflix, Twitter, Microsoft, and many more. The language has played a large part in the cloud infrastructure domain as well, with Docker, Kubernetes, and Terraform being the most well-known.

The Go language also has the most recognizable mascot of all the languages, with the Go Gopher. You can even play with the images, but you must give credit to the creator, Renée French, when used.

Go logo example adapted from Renée French's creation

Go logo example adapted from Renée French's creation

Let's have a look at the differences between Go and other popular languages for DevOps.

Compiled vs. interpreted ^

Go is compiled, whereas many DevOps languages, such as Python, PowerShell, and JavaScript, are what is known as interpreted.

A compiled language converts your source code directly into machine code. An interpreted language looks at your code line by line to make it run. There are advantages and disadvantages to both. Here is a high-level view:

Compiler

  • Source code privacy
  • Fast
  • Platform dependent
  • Reads and analyzes the code only once

Interpreter

  • Can work across platforms
  • No source code privacy
  • Slow
  • It reads and analyzes the code statements one at a time

Another big advantage here is that Go binary doesn't just contain our program, but all the support code required to run the code. The result is a lightweight binary file to deploy without required Go tooling to run on the machine.

Languages such as Ruby, Python, and JavaScript are required on a machine to run the code, along with many files that go with your program. We can also tell it to compile to a different architecture, such as Linux, Windows, or MacOS.

Statically vs. dynamically typed ^

Another main difference of Go to languages such as PowerShell, Python, and JavaScript is that it is a statically typed language, whereas those three scripting languages are dynamically typed. Go will check data types for errors at compile time, which results in fewer errors at runtime. With a dynamic language, there will be no checks done until runtime.

With Go, you define a variable type at compile time, which will remain unchanged throughout the execution of a program. Dynamic languages don't specify the type of the variables, which are checked during execution. If you write a program and it is peer-reviewed by a colleague, it can be quicker to identify values with a static typed language than with a dynamic language, as you can clearly identify the type.

Static languages require less boilerplating. Here is a simple example of Hello world written in Go and Python:

func hello(name string) {
  fmt.Println("Hello " + name)
}

def hello(name):
print("Hello " + name)

The problem with the Python example is if I just want a string, I have to add extra code to stop someone from putting in a bunch of integers. With the Go example, only a string will be accepted; otherwise, an error will be thrown.

Go concurrency ^

Another powerful feature of Go is concurrency, which is the ability of a program to do multiple tasks at the same time. In languages such as Java and Python, concurrency splits its tasks into smaller subtasks, which are then processed in parallel using threads. Go is a bit cleverer and has built-in concurrency constructs called goroutines and channels.

Goroutines are Go's lightweight approach to threading. Go uses channels as its favored way to communicate between goroutines. Goroutines are very memory-light to create and only take a few additional KBs.

Why I use Go ^

These are just some of the reasons why you might want to consider Go as a language of choice. I've been on my journey with Go for just over a year. My primary reason for using Go is to write Infrastructure as Code on AWS with a tool called Pulumi. Pulumi allows the freedom to write Infrastructure as Code with your language of choice.

Having used Python then JavaScript/TypeScript, I started to get interested in Go, knowing it was statically typed and is simply a smaller language compared to Python or JavaScript. Performing a task in Go is simpler, as there is usually only one way compared to other languages, which can have several ways to do the same action.

Go comes with some handy tools built in. Go is usually formatted in a particular way that conforms to Go conventions. The Go command line has a feature named fmt. Running go fmt will automatically format your code in keeping with these Go guidelines.

When it comes to the number of keywords available, Go has just 25, compared with JavaScript's 49. For this reason, learning Go and all its features will take less time than choosing one of the other DevOps languages.

I urge you to look at Go and start with a Tour of Go on the Go website. The examples in the guide provide a walkthrough of the many aspects of the language.

0 Comments

Leave a reply

Your email address will not be published.

*

© 4sysops 2006 - 2022

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account