Golang Made Me Love Programming Again

When I was a teenager, I wrote C.

When I was 13, I got a copy of Just For Fun, Linus Torvalds' autobiography. The Blizzard of 2003 happened during February vacation that year, and I figured what better way to spend it than implementing an operating system.

So, I attempted it, in C and i386 assembler. It never got further than giving a single-task shell (in protected mode, though!) that could peek memory locations.

A couple years later, I spent a whole summer just banging out code. The big project was fakedbfs, initially intended to implement BFS’s (BeOS Filesystem) metadata functions in userspace on top of SQLite in FreeBSD (and Linux, I guess). This was before FUSE was ubiquitous, and I never quite got to the VFS implementation. But it did have a schema parser and compiler, a querier, and its own query language that mapped a subset of tokens to SQL. This and the schema parser were inplemented in lemon, the same LALR(1) parser used by SQLite itself. I used it to catalog and search my growing music collection; it had pluggable (using dlopen(3)) extractors for ID3 and Ogg tag metadata. You could query things like genres, albums and years, and as a budding 70s rock trivia nerd, life was good. I was 15, and I was proud.

When I was 21, I got a job at a small local digital marketing company as a junior developer (of two). We were very much a LAMP(HP) shop (hi Craig!) and life was simple, but in my heart I always yearned for the spartan nature of the C programming environment on Unix. Even later in my career, I found myself implementing things in C in ways that may be considered malfeasance today, like a program that accepted emails from an /etc/aliases pipe alias and maintained a local SQLite database for sending out reminders to file mortgate insurance binders (when I worked at a lender as a one-man show IT youngun who also happened to be able to do Encompass360 business logic). Oh boy. I bet you’re noticing a theme, with all the SQLite. SQLite is awesome.

Today, as I said, that would be considered malfeasance. I’m no slouch in C, and I always use safe, bounded library functions and meticulously manage the memory of every object I allocate. But even the most diligent, talented masters make mistakes, and I am far from a master.

Enter Golang.

On amd64, a function call in golang is around 6 instructions, last I heard. Even if it isn’t anymore, it is obvious that Golang was designed with particular attention to the balancing act of efficiency, safety, and code that is a pleasure to read. I’ve never been a fan of garbage collected languages, but I guess this is one of the tradeoffs that we can make: computers are fast enough, and the benefits are immense. Of course, I want to learn Rust, because GC is not really acceptable at the kernel level, and I am curious as to how much of a pain (or a simple paradigm shift) RAII is. But after writing Go full-time for 3 months now, I really can’t be bothered to care, at least in any domain above the kernel and where protobuf, JSON, and YAML are spoken regularly.

Golang’s type system is a work of art, as someone who eschewed OO for a long time. Golang’s flavor of OO is just plain delightful (and yes, even without true generics). Interfaces are delighful, and yes, I know they are not novel to Go. Go is certainly a multiparadigm maverick, allowing you to think as an instruction-conscious C programmer who has native strings, and as a functional programmer whenever it may suit you. “Functions as first-class objects” really just seems like an area where C was so close, yet so far. It could be done, but it was ugly and dangerous.

Golang’s concurrency primitives (and strong standard library support) are a joy to use. I also wrote a program called phoned the next summer, before I knew what Asterisk even was. It was an answering machine for voice modems, and it could broadcast caller ID data over the network for consumption by utilities xcid (for X11) and CIDClient, written in VB6 for Windows. Yeah, I know. It had a Telemarketer command, which would pick up the phone and hang up after two seconds. phoned made heavy use of pthreads, and I learned a lot about locks and semaphores that summer, but boy, was it arduous, and nothing like goroutines and channels.

Having the benefits of strong typing, closures, and concurrency in a modern, string- and web-filled context is just plain awesome, and it has me loving programming again, just as I did when I was a kid holing up in his bedroom writing thousands of lines of C.

Posted on September 26, 2021