Getting started with Go (and Emacs)

Dumping some notes I took while I was setting up my environment and reading the bare minimum to get started with Go programming.

Go setup

Emacs setup

In the last couple of years the Emacs LSP integration has got good enough that, other things being equal, I prefer it when I’m setting up a new language since it provides a similar out-of-the-box experience to what I’m used to, without much extra configuration.

This is what my Emacs config looks like:

(require 'lsp-mode)
(require 'go-mode)

(add-hook 'go-mode-hook 'lsp-deferred)
(add-hook 'go-mode-hook 'subword-mode)
(add-hook 'before-save-hook 'gofmt-before-save)

(add-hook 'go-mode-hook (lambda ()
                          (setq tab-width 4)
                          (flycheck-add-next-checker 'lsp 'go-vet)
                          (flycheck-add-next-checker 'lsp 'go-staticcheck)))

The only issues I’ve found so far:

GitHub setup

Go documentation

I had read The Little Go Book a few years ago, and while I didn’t do anything with what I read there and thus forgot most of it, I did remember that there wasn’t anything surprising or complicated enough to require dedicated training before attempting to use the language.

This time I took a look a Go’s learn and docs pages, but they didn’t point me in a single obvious direction. There was the Effective Go book, which sounded like the kind of resource I tend to favor: text form, not very long, by the language authors. But it started with a note saying it was written in 2009 and hadn’t been updated since, which made it unappealing for my short-term goals. I may revisit it eventually, though, since I understand it was the canonical learning resource for many years and a good showcase of Go’s idiosyncrasy.

I turned to the official tutorials, but after the first hello world they got into the weeds of modules and workspaces, without enough context for them to be useful starter resources. (In fact, they side-tracked me to read more about modules and project layout, to try to understand how Go compares to other languages on those fronts).

What ended up working for me was just trying to implement my project’s basic features, starting from the hello world program, looking up what I didn’t know in Go by Example (which had at least preliminary answers for most of my questions), then jumping to the package documentation for details. I’m sure I missed out on language features and idioms, but it was amazing to start making steady progress just a day after first installing Go.

I took note of some resources I could go back to, to dive deeper into the language once project development winds down:

I will elaborate on my first impressions of the language in a later post.