This is the first tutorial in our Golang tutorial series. This tutorial provides an introduction to Go and also discusses the advantages of choosing Go over other programming languages. We will also learn how to install Go in Mac OS, Windows and Linux.
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 is a general-purpose programming language with a simple syntax and is backed by a robust standard library. One of the key areas where Go shines is the creation of highly available and scalable web apps. Go can also be used to create command-line applications, desktop apps and even mobile applications.
Advantages of Go
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.
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
Concurrency is an inherent part of the language. As a result, writing multithreaded programs is a piece of cake. This is achieved by Goroutines and channels which we will discuss in the upcoming tutorials.
The Go compiler is pretty amazing and it has been designed to be fast right from the beginning.
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.
Tooling deserves a special mention in Go. Go comes bundled with powerful tools that help developers write better code. Few of the commonly used tools are,
- gofmt - gofmt is used to automatically format go source code. It uses tabs for indentation and blanks for alignment.
- vet - vet analyses the go source code and reports possible suspicious code. Everything reported by vet is not a genuine problem but it has the capability to catch errors that are not reported by the compiler such as incorrect format specifiers when using Printf.
- golint - golint is used to identify styling issues in the code.
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.
Simple language specification
The language spec is pretty simple. The entire spec fits in a page and you can even use it to write your own compiler :)
Last but not least, Go is an open source project. You can participate and contribute to the Go project.
Popular products built using Go
The following are some of the popular products built using Go.
- Google developed Kubernetes using Go.
- Docker, the world famous containerization platform is developed using Go.
- Dropbox has migrated it's perfomance critical components from Python to Go.
Go is supported on all the three platforms Mac, Windows, and Linux. You can download the binary for the corresponding platform from https://golang.org/dl/
Download the Mac OS installer from https://golang.org/dl/. Double tap to start the installation. Follow the prompts and this should have Golang installed in /usr/local/go and would have also added the folder /usr/local/go/bin to your PATH environment variable.
Download the MSI installer from https://golang.org/dl/. Double tap to start the installation and follow the prompts. This will install Go in location c:\Go and will also add the directory c:\Go\bin to your path environment variable.
Download the tar file from https://golang.org/dl/ and unzip it to /usr/local.
Add /usr/local/go/bin to the PATH environment variable. This should install Go in Linux.
In the next part Golang tutorial part 2: Hello World of this series, we will set up the Go workspace and write our first Go program :)
Please provide your valuable feedback and comments. Thanks for reading.
Next tutorial - Hello World