Advent of Code 2023. Go Figure.

Advent of Code 2023. Go Figure.

ยท

6 min read

2022 - History

In November of last year, my older daughter proposed that she, her brothers and I participate in Advent of Code (AoC). While I didn't know anything about AoC except what my daughter described, this sounded like it could be fun. Each of us is a professional software developer (engineer?) with a strong streak of curiosity and a competitive spirit.

If you aren't familiar with AoC, it is an annual software-development-focused, problem-solving competition that runs from Dec 1st to Dec 30th -- the season of Advent, hence the name.

During the competition, part one of that day's challenge is published on the AoC website at midnight EDT. Using any technology stack, development language, or computation tool, each competitor must solve the problem -- Part One and Part Two -- as quickly as possible. The description of the problem and competitor-specific input data are provided by AoC. The criteria for success is entering the answer -- always a single number -- into the AoC website page. When the correct solution to Part One has been entered, AoC provides Part Two of the problem which generally increases the complexity of the Part One problem.

Past solutions have been crafted in every imaginable development language with the possible exception of IBM System 370 Assembler. In 2022, the leaderboards for AoC were dominated by participants who used generative AI tools (e.g., ChatGPT). Every day, solutions were posted in under a minute, sometimes within seconds. The outcry from "legitimate" competitors was deafening. For 2023, the use of AI tools has been strongly discouraged, at least for the official competition. Yeah. RIght.

...but I digress. Back to the story

For my family, the 2022 challenges were fun for the first week or so. As the difficulty increased, the solutions became more time-consuming... much more time-consuming.

Since we all have real jobs that pay the bills and real lives, one by one each of us found it necessary to drop out. By the beginning of Week 3 (Day 15 or 16), we were done. I will only say that I was the last of our group to drop out... and that finishing AoC could have become a full-time pursuit by the end of the month! In the end, the only clear winner was AoC. It had beaten us! ๐Ÿ˜ณ

2023 - Thistory ("this story" ๐Ÿ˜‰)

This year, my daughter and two sons opted out of AoC leaving me and my oldest son, Marshall. Not surprisingly, we had the same idea. Rather than using AoC as an individual competition, we could collaborate on the problems and use AoC as an opportunity to learn (a) a new language and (b) spend more time together. We decided to ignore the "competition" element of AoC -- ignoring the leaderboard completely -- and to move at our own pace since our objectives were decidedly not competitive. After agreeing on this approach and after some discussion, we decided to use Go as our development language this year.

As of today, AoC 2023 has posted 11 daily challenges. We finished the first 4 days' challenges rather quickly, learning some fundamentals of Go coding. Day 5 was a decidedly bigger challenge. We decided to dive deeper into Go and take our time solving this problem. We definitely weren't after the fastest solution, but certainly one that provided the correct answer.

Over a period of 8 days -- off and on -- we wrote some pretty wicked Go code -- delving into objects, separating code into packages, playing with generics, writing go-routines that use channels, etc. Generally, we were shaking down Go based on our experience with literally dozens of other languages (e.g., C, C++, C#, COBOL, Fortran, JavaScript, Rust, LUA, et al).

Our solution to Day 5 was big... and slow ๐ŸŒ. Part 1 only ran for a few seconds. Part Two ran for 40 minutes. This was after implementing go routines to get parallel processing and consuming 10 AMD Epyc CPUs (on a 24-CPU Linux host). This was the epitome of the "Brute Force" approach ๐Ÿคฃ. Thankfully, the answer it produced was correct ๐Ÿ˜ฎโ€๐Ÿ’จ.

Go - Hysteri-a

Now, for my thoughts on Go. Already, it's a love-hate relationship -- on many levels.

While Go syntax is more or less like other members of the C/C++/C#/Java/Javascript family, there are some departures. In general, it feels like Go does not provide the economy of expression of some other languages. Take, for example, another, more performant solution for AoC 2023 Day 5f, I mean that equivalent functionality in Go and, for example, Typescript

The syntax for defining objects, methods, and interfaces took some time to feel "normal". In particular, the lack of (a) function overloading, (b) optional function arguments, and (c) default argument values means many additional, uniquely named functions to cover the various signatures required in a library. If you are the library's author, that can be a lot of extra code to maintain. If you are the library's consumer, it can mean a confusing list of annoyingly similar but different method or function names to navigate.

Error handling in Go is also idiosyncratic. The idiomatic practice of a function returning a second value to report an error -- or just ok -- makes it all but impossible to chain function and/or method calls together in the style of so-called fluent APIs. This is touted as one of Go's strengths, but I find it somewhat annoying. It certainly creates more verbose code.

The highly opinionated Go toolchain also takes a bit of settling in. You just have to get used to the fact that your IDE with Go tools set up is going to reformat your code every time you save your code... and your code won't run if there's any kind of an error in syntax, usage, type-matching or whatever. You simply MUST fix these things.

On the other hand, the efficiency and speed of the GO toolchain and your compiled programs -- WOW! It's just amazing. Likewise, the small size of your compiled programs.

Finally, Go has been around a while (see the Wikipedia article in the footnotes) and the amount of information available from the official website, StackOverflow and other independent sources is pretty substantial. A Google search for a go-related issue generally turned up a solution in a minute or two.

Conclusions - Mastery

In the first 10 days, it is clear that we are already achieving our objectives for AoC 2023. We have learned a lot about Go, spent more time together, and committed to continuing our efforts on the AoC 2023 challenges into 2024, albeit at a more leisurely pace. We'll still be using Go to develop more proficiency, but we'll move forward at a more leisurely pace.

If you are a professional developer these days, knowing something about Go is, at the very least, helpful. For some, it's required knowledge. The good news is that, in a week or so, you can get a pretty solid foundation in Go and be off to the races.

ย