Advent 2021: Go
This blog is part of the 24 posts long series "Advent 2021":
- Advent 2021: Intro (December 01, 2021)
- Advent 2021: C++ (December 02, 2021)
- Advent 2021: C# (December 03, 2021)
- Advent 2021: Python (December 04, 2021)
- Advent 2021: Go (December 05, 2021)
- Advent 2021: TypeScript (December 06, 2021)
- Advent 2021: CMake (December 07, 2021)
- Advent 2021: Django (December 08, 2021)
- Advent 2021: Angular (December 09, 2021)
- Advent 2021: Flask (December 10, 2021)
- Advent 2021: gRPC (December 11, 2021)
- Advent 2021: GraphQL (December 12, 2021)
- Advent 2021: XML & JSON (December 13, 2021)
- Advent 2021: Matplotlib, Pandas & Numpy (December 14, 2021)
- Advent 2021: Linux (December 15, 2021)
- Advent 2021: Ansible (December 16, 2021)
- Advent 2021: SQLite (December 17, 2021)
- Advent 2021: Catch2 (December 18, 2021)
- Advent 2021: Zstandard (December 19, 2021)
- Advent 2021: ZFS (December 20, 2021)
- Advent 2021: Thunderbird (December 21, 2021)
- Advent 2021: Visual Studio Code (December 22, 2021)
- Advent 2021: Blender (December 23, 2021)
- Advent 2021: Open source (December 24, 2021)
This is a rather interesting entry for me. I’ve been programming for many years and regularly picked up new languages, but mostly out of necessity, not because I was that keen to try out something new. In recent years there have been a few new languages that piqued my interest, notably: Rust and Go. New might be a strong word here as Rust is 11 years old and Go is 12, so let’s go with increasingly popular.
I sometimes do occasionally want to write a small, efficient, super quick to startup tool, or a small, network enabled application. Go is great for that. Or you want a small gRPC client to deploy to your Raspberry Pi? Go is a language that excels in this area for a few reasons:
- It’s simple (and simple to use).
- It has a mature ecosystem.
- It’s robust.
Let me elaborate a bit on each of those. I enjoy using a simple language that works and where I can come back after a while and still understand what I wrote. Go is not my main programming language but it does really well in this department. The syntax is a little bit intimidating if you’re only familiar with C-style languages, but nonetheless I think it’s reasonably easy to understand, even if you never saw Go before. Let’s look at an example here:
func Load(stream io.Reader) (*Settings, error) {
settings := NewSettings()
data, err := io.ReadAll(stream)
if err != nil {
return settings, err
}
if len(data) == 0 {
// Empty file
return settings, nil
}
err = json.Unmarshal(data, &settings)
return settings, err
}
Does it look weird? The error handling, maybe, but other than that it’s quite straightforward, and that is a plus in my book. Complex code obviously does look rather complex, but most of the time it’s fairly simple.
The mature ecosystem is also a big bonus for Go. If you want to write a small tool, the last thing you want is picking between 5 different half-baked JSON parsers, and you can see that Go has been used a lot in professional environments. There are libraries available for not so fancy use cases like PostgreSQL bindings and other things you typically don’t see much love for until a language is used by companies a lot.
Finally, it’s a robust language. Memory management is automatic, and the tooling will capture most common bugs during compile time. I was really surprised how quickly I managed to write a working program with good error handling. Go makes this feel really natural and combined with near-instant compile times, fast startup, solid debugging capabilities, and excellent cross-platform support, it’s been a joy to use so far.