Skip to content

Go’s new brand finally convinced me: let’s learn Golang

Go Logo. Copyright 2018 The Go Authors

Every single programmer that has worked with either C or C++ has learned to maintain a love-hate relationship with them. They are powerful, efficient and pretty much everywhere, from embedded devices to high-end servers. However, they are also a pain to work with. Taming those languages requires experience and a lot of hard work, even for the most basic tasks.
Despite all of their drawbacks, I still like working with them. But deep in my soul I was craving for a modern alternative, with their advantages but without having to sleep with a 1000+ pages long C++ reference by my side.

So enter Golang. High performance, off-the-shelf concurrency, readability and created and maintained by almighty Google. A “Shut up and take my money” kind of deal.
However, I was afraid that it was going to be another trend, a new language that would raise in popularity and then thrown away with despise. But years have passed and it does not seem to be the case. It’s still popular (although perhaps not ubiquitous), and one of the most popular projects nowadays, Docker, is built using it.
But the reason that has made me finally decide to learn Go is the fact that it has a new brand image, fresh and cooler. You might think that it is an stupid reason for taking up a new language, and it is. But hey, we live in a visual culture age, or so they say.

Getting started

In Ubuntu is pretty easy to install golang.
sudo apt install golang
And that’s it. This provides us with the go executable, which can be used for the following things (among others).

  • go build: compile packages and dependencies (it generates and executable)
  • go run: compile and execute the program in a single step
  • go clean: remove compiled files

In addition, it also provides tools for working with packages. Unlike C++, Golang organizes source files in packages, which groups objects (including functions but also variables, types and constants) that provide related functionality to be used by other programs.
Packages can be easily defined with the package <package_name> line in your source file. In this manner, when the package is installed using `go install`, it will be possible to import it in other source files and use functions defined in the package (simply remember to start the function name with a capital letter if you want to make it available).
For external packges, go get can be used. For example.

go get

Another useful command is go env, which tells us the values of the environments variables being used by go. This can be important for installing remote packages and troubleshooting.

Editing go source files: vim-go

The most important topic of all, what editor to use. I will not say that vim should be your weapon of choice, but if you use something else you should feel ashamed of you existence.
In order to work with go in vim, a good options is using the vim-go plugin.
Firstly, it brings color syntax for go, but is also has interesting features such as consulting documentation, renaming objects, installing packages and so on.
To install it using vim-plug add this line to .vimrc:
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }

Learning path

Instead of reproducing more examples that you can find elsewhere, I believe that is more useful to point to some useful sources that I have used myself to learn go.

A Tour of Go

The official introductory course to go. It covers go’s key features, including data types, methods and interfaces and concurrency. The course is organized in modules and it includes an interactive console that allows you to execute example programs that illustrate the concepts being studied.

Go by Example

A pretty self-explanatory title: a list of examples that focus on specific aspects of the language. It goest a little bit beyond the content of “A Tour of Go”, with examples about more realistic problems such as mutexes, file I/O and spawning non-go processes.

Go wiki

Official wiki covering the whole language. In particular, I consider the Articles specially helpful, since they presented in a more visual and user-friendly way.

Awesome Go

Following the tradition of many other Awesome lists, Awesome Go presents a curated selection (by the way, “curated” seems to mean nowadays that “this is not another shitty list that I have copied from somewhere else”) of Go-related stuff (frameworks, libraries and software). If you are looking for the right tool for solving a problem that you are facing, this is a good place to start.

Closing remarks

This curated article (curated, that magic word) has attempted to provide some motivation regarding taking up Go as a programming language. If anything, Go brings fresh air to the scene of system languages. It is ellegant and easy to use, and it is backed by a huge organization. It might never become a completely mainstream language, but I am sure that it will stay with us for many years.
If you are not convinced yet, I recommend revisiting some of your C++ code and suffer remembering how much did it cost to make it work. Or take a look at some of the numerous articles which describe why C++ sucks.
But renember, the most important reason is that Go has a new brand which looks good.

Published inGo

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *