* article elaborated in partnership with Andreia Camila da Silva
The previous post introduced a notion of the language and where to start your studies in Go. In this post, we will give you the reasons to use Go.
Before listing the reasons, let's take a look at some results from the 2020 edition of the Developer Survey, conducted by Stack Overflow. Go is ranked 12 in the most popular technologies ranking.
Nevertheless, it is among the 5 most loved languages of the year.
The survey shows a very interesting contrast. It seems Go has not yet gained a comprehensive share of the market. At the same time, it is among the most loved and desired languages by developers. This article aims to list some interesting features of what may become your favorite language. So, hey ho, let’s Go!
Go has a lean and simple syntax, with few keywords to memorize, enabling rapid learning. Even for developers used to other languages like Java and C, Go presents a shallow learning curve. It's the kind of language that makes the programmer read a book or the documentation itself and wonder: "But is that all?"
It is common to hear that Go is a fast programming language. One of the reasons is that the code developed in Go is translated by the compiler into native machine code, generating considerably small binaries. The Go compiler is very effective in detecting pre-compilation failures and even preventing possible "waste" such as variables or unused imports. There is no need to use VMs.
It is possible to generate Go code executables for several platforms through the $go build command, informing the operating system and target architecture through the GOOS and GOARCH environment variables. This way, the source code will remain intact.You can also cross-compile your application into a docker container, check out here.
Garbage Collector will reclaim memory occupied by objects that can no longer be referenced within the scope of execution. It is processed simultaneously, during the execution of the Go program.
Go has very efficient and lightweight support for simultaneous code execution through goroutines and channels. Goroutines are analogous to threads, but at a considerably lower cost. To create a goroutine just add the keyword go before the desired function is called (or through anonymous functions). This will cause it to be executed as usual, but the program will not wait for a response before proceeding to the next instruction. The channels, on the other hand, make communication between goroutines possible, allowing the exchange of values between them through the send and receive operations.
As mentioned in the previous post by Morvana Bonin, several cloud technologies have their core developed in Go. This is something that leads us to believe that the language is not only suitable for cloud development, but also composes it. In this interview, Steve Francia, Product and Strategy Leader of the Go language, comments that "It would be reasonable to say that the modern cloud is written in Go". Another advantage is the Go Cloud Development Kit, which provides APIs that assist in the development for major cloud providers.
Go has an attractive range of features, which can also be found in other languages, but are not always combined. On the other hand, because it values simplicity, it does not have certain conveniences such as exceptions, generics, overload of functions, inheritance or annotations. In the book Go In Action, the author mentions that "Go is not only defined by what it includes, but by what it does not include". It is with this thought that we come to the end of this article.