Why Go?

Anam Shah
Technogise
Published in
4 min readAug 29, 2019

Introducing Go

Go, also known as Golang, is an open-source, compiled and statically typed programming language developed by Google.

The key people behind the creation of Go are Rob Pike, Ken Thompson, and Robert Griesemer. Go was made publicly available in November 2009.

Go compiler was initially built in C but now it is built in Go itself.

So what’s so special about Go?

  • Golang is compiled and statically typed programming language.
  • It supports built-in concurrency with the help of GoRoutines
  • Built-in garbage collector and memory safety.

Advantages of Golang

Why would you choose Go as your server side programming language when there are tonnes of other languages such as Python, Ruby, NodeJS… that do the same job?

Here are some of the pros which I found when choosing Go.

Simple syntax

The syntax is simple and concise and the language is not bloated with unnecessary features. This makes it easy to write code that is readable and maintainable.

Easy to write concurrent programs

This is probably the most praised feature of Go. It has supported concurrency ever since its birth. It can fully utilise multi-core capability. Golang uses goroutine to achieve concurrency and it provides a very elegant goroutine scheduler system which makes it easy to spawn millions of goroutines.

Compiled Language

Go is a compiled language. The source code is compiled to a native binary. This is missing in interpreted languages such as JavaScript used in NodeJS.

Fast compilation

The Go compiler is pretty amazing and it has been designed to be fast right from the beginning.

Static linking

The Go compiler supports static linking. All the Go code can be statically linked into one big fat binary and it can be deployed in cloud servers easily without worrying about dependencies.

Garbage collection

Go uses garbage collection and hence memory management is pretty much taken care automatically and the developer doesn’t need to worry about managing memory. This also helps to write concurrent programs easily.

Go intentionally leaves out many features of modern OOP languages.

No Classes

Everything is divided into packages and struct instead of class

No Inheritance

By removing inheritance, Go makes it easy to understand the code also (as there is no super-class to look at while looking at a piece of code).

No Assertions

Go believes that programmers use assertions as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue to operate instead of crashing after a non-fatal error. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.

No Exceptions

Go believes that coupling exceptions to a control structure, as in the try-catch-finally idiom, results in — (a) convoluted code.. and (b) programmers labelling too many ordinary errors (..such as failing to open a file..) as exceptional.

Go takes a different approach. For plain error handling, Go’s multi-value returns make it easy to report an error without overloading the return value. A canonical error type, coupled with Go’s other features, makes error handling pleasant but quite different from that in other languages.

Go also has a couple of built-in functions to signal and recover from truly exceptional conditions. The recovery mechanism is executed only as part of a function’s state being torn down after an error, which is sufficient to handle catastrophe but requires no extra control structures and, when used well, can result in clean error-handling code.

Above changes make Go very different from other languages and it makes programming in Go different from others. You may not like some points from above. But, it is not like you cannot code your application without above features. All you have to do is write 2–3 more lines. But on the positive side, it will make your code cleaner and add more clarity to your code.

Open Source

Last but not least, Go is an open source project. You can participate and contribute to enhancing it further.

Disadvantages of Golang

Error handling

Go programs require the function to return an error if there might be an error expected. This may cause problems where the track of the error is lost, which leads to missing useful error handling logic. There are tools which can help detect this kind of miss such as errcheck. But they are more like workarounds. Also, developers need to write lots of if blocks to check error and handle it which makes the code less clean.

Package Management

Package management in Go is not perfect either. By default, it cannot create a dependency tree with fixed package version, this means the build created may be based on a different version of packages when building at different time. There are tools which can help detect this kind of miss such as dep. But again, they are more like workarounds.

--

--

Anam Shah
Technogise

Made in India, Programmer + Traveller, Startup enthusiast, Love Coding