Learn Golang in 1 Month

30 June 2016

At my new job we have a Go backend. It’s a nice language with familiar syntax. Someone with C, C++, C# or Java experience will feel right at home. A language designed to make Software Engineering easier. At the same time it’s being sought out to address bottlenecks in Ruby, Perl, Node.js and Python codebases.

We chose Go because it seemed like a useful tool to understand for building large software systems. The Scripting languages are among the slowest, Go is compiled into a binary so no runtime is spent interpreting. A binary also makes the deployment process painless as you can just scp the file around. Go is a modern language with first-class concurrency primitives. It’s been designed to leverage modern hardware with multiple cores.

Go is a language designed in the service of software engineering. Other programming languages come from academia Haskell, OCAML, ML, etc. Go on the otherhand was designed to solve problems faced at Google. One such problem is software management. Meaning, how do we deal with codebases which are millions of lines long? How do we deal with version skew over time? Go is designed to be a very concise language. It’s spec is among the smallest of any language. Such conciseness allows for the creation of code reading tools. Tools like gofmt, gofix and godoc. The language also lacks class-inheritance favoring the gang-of-four’s Composition over Inheritance pattern.

Go: 90% Perfect, 100% of the time

Source: Program your next server in Go

Syntax

Getting Started

  • Do How to write Go code to get some basic environment issues out of the way and learn how to call go functions from different files and packages. Doing this first would have saved me some headaches.
  • Go Tour The defacto tutorial for Go.
  • Go By Example Learn Go by following examples
  • The little Go Book A good self contained resource

Community

  • IRC Freenode #go-nuts chat channel. They get pretty pedantic at times and frequently refer you to the Spec.
  • Gophers Slack has regional chatrooms as well as topic specific ones.

Exercises

Read the Official Blog

The Go team has developed a very good blog. All the articles are very good and essential actually for many useful go tools like go test and go doc. Useful for staying up to date on language news.

Web applications

JSON

Godoc

Use Godoc to document your programs, it’s very good and everyone uses it. We use it at Capsule to generate our internal API documentation.

  • Work through Documenting Go Code
  • godoc Godoc Read the doc on the tool for usage.
    • Run godoc -http=:6060 -goroot=. assuming you’re in a project’s directory. godoc docs are designed to give you a snapshot of all go code on your machine. Once you have this running you can see the docs by navigating to http://localhost:6060/

Object-Oriented

The way Object-Orientation is achieved in Go differs a bit from languages like Java or C#. The main facility is via interfaces. This approach helps avoid long class hierarchies.

Go playground

Here are some code samples I’ve written over the past couple of months. Every time I learned something or made a new insight into Go as a noob I ended up making a playground demo and tweeting it. Hopefully some of them are useful to someone else.

Videos

Advanced

Theory

Why Go is the way it is

Some literature from one of the author’s of Go, Rob Pike, on Go’s design.



comments powered by Disqus