moddedbear.com

Learning Go With Advent of Code

Anyone following me on Mastodon or the wider fediverse has probably already gotten an earful about this, but I’ve been trying my best to keep up with Advent of Code this month. Even though it wasn’t my intention when I started out, I’ve been using Advent of Code’s daily challenges to teach myself Go.

I’ve been a bit curious about Go ever since I found out about it a while back and figured this was a good a chance as any to dive into it. I started by rewriting some of my already completed Python solutions in Go. This was a great decision because I didn’t have to think about a working implementation plus a new language at the same time, and this was early enough in the month where solutions were pretty small.

Before long I moved on to tackling the problems in Go from the outset. Now most of my solutions are in Go, though I still occasionally fall back to Python when it’s better suited for the problem.

It’s been over a week with Go now and it’s shaping up to be one of my favorite languages. Writing in Go to me sort of feels like some sort of blend between a C-like language and Python. You get a fair amount of control without sacrificing usability and readability too much.

I’ve compared the runtimes of my Go and Python solutions for challenges where I wrote a solution in both and the Go solution is always several times faster. No surprises there – Python is interpreted while Go gets compiled. It’s just nice to see Go have such an advantage there when it isn’t that much harder to write than Python in my opinion.

I’ve only just barely scratched the surface of importing external modules (I used a hashset implementation in a couple of my solutions) but that seems pretty straightforward too.

The other language I started learning this year was Rust, and while there’s a lot I liked about that too it seems it’s best suited for systems programming – not quite what I’m into. Go on the other hand I can definitely see myself using more in the future.

adventofcode.com
My Advent of Code solutions on GitHub

#programming

↪ Reply