Me and the elves - Advent of Code 2022 retrospective
Another year of Advent of Code is over and it's time for a retrospective. In 2022, I finished the year with 38 stars.
Surprisingly, I've grown as a developer
In the past year and a bit, since last year's Advent of Code, I've been exploring extra puzzles from previous years, starting with the first (2015). So when this year rolled in, I had more experience in solving these with my chosen tool set - Python and Jupyter Notebooks.
This year, I could totally see the impact this experience has brought. There are a lot of puzzles (for example, day 13) that would have been triggered a "yikes" reaction from me before but this year was "oh cool" reaction. I've also been able to solve these puzzles way easier than in previous years which has been fun.
Few specific areas that I've gotten more comfortable with are my usual weaknesses: recursion and trees. There's still one major gap and that's math but that's something I would have to look into other sources to get better at it.
What I mean by math is the ability to recognize what mathematical concept I should apply and how. For example, with day 11, I immediately noticed that math is needed but I probably would have never figured out alone on my own that I need to find the least common multiplier. Once I was nudged to the right direction by the help from community, I was able to plug it in and get the puzzle solved.
One thing I really like to see is that I've become better at refactoring my solutions into elegant and easier to read code. There were some days when I was traveling or busy with work and didn't have time to focus on that but for example day 13 ended up with some of the most beautiful code I've probably ever written.
And I'd like to think my explanations and associated writing in general has improved but that's a question you'd need to ask someone else. I did get a lot of positive and encouraging feedback from readers this year so I'm happy.
Now with more doctest
I haven't really been writing much tests for Advent of Code puzzles in the past. Last summer, I took a look at options in testing tooling for Jupyter Notebooks and this year, partly inspired by Paolo Melchiorre's use of doctest, decided to go with it where necessary.
I'm not testing every function but whenever I run into issues or see upfront that things might be harder than I'm comfortable solving, I do test-driven development (TDD) with doctests. I'm not still sure if I like doctest that much. There are benefits and downsides that I went into more depth with the blog post linked above. It makes browsing through the code harder when a 10-line function might have 20+ lines of docstring.
For the first half of December, I struggled with debugging because every
On the 13th, I learned that I can print to
sys.stderr and that will solve all the issues I had. Now it's much more enjoyable to use doctest.
Especially for functions that use more complex operations or recursion, doing TDD with doctest often helps the complexity to build up manageably and without even noticing as I can go case by case and at some point, everything just works and I can refactor.
With Jupyter + doctest combo, changing the interface of functions became a pain though. If I needed to add another return value, I'd have to painstakingly go through all the doctests and change them. With proper code editor support, that could have been easier. VS Code supposedly supports developing Jupyter notebooks but I haven't tested that out yet, I've always used notebooks via a browser. Maybe in 2023 I'll explore that option.
Community still rocks
Every time I write or talk about Advent of Code anywhere, I keep saying the same thing: it's so much fun to solve these puzzles with fellow community members. I usually try to solve mine first alone and if successful, I'll celebrate and share with the community. If I get stuck or don't understand something, I'll reach out to people and always find people willing to help.
And it's so cool to see other people's solutions in so many different languages and learning from those. And seeing how other people solve and approach the same puzzles with the same tools but in a widely different manner.
So big thanks to my fellow puzzle solvers in Koodiklinikka, Asteriski, Lumberchill, Mozilla and Mastodon communities.
December full of travel and work
In 2021, I was on a burnout leave for the entire month and Advent of Code was the perfect distraction from everything. This year, I was bit worried I might not be able to participate fully as I had 15 travel days within these 25 days + a job I started recently.
Turns out, it wasn't much of a problem at all! With my improved coding skills and a relaxed attitude towards those days when I knew I couldn't do as much refactoring or explaining, I was able to solve the problems first thing in the morning before heading to work or events. And for those travel days when I was in a train or a ferry, I used my limited internet availability in a smart way and was able to focus on the development with local environment.
I did end up skipping most of the final days due to spending the days with family and prioritizing that over being stuck with the obsession to complete these puzzles. That proved to be a fantastic idea: I felt zero stress or anxiety about the need to reach 50 stars.
My workflow for this year was:
- Solve the problem, get the stars
- Come back to the solution and do first pass of writing explanation
- Refactor and polish code and change or add explanations accordingly
- While discussing with others, new ideas or approaches pop up
- Refactor those into the original solution or write an appendix
There were a few days when the puzzle was either too hard or the day was too busy but the amount of those was way smaller than I had expected. Day 22 gets a special mention though: I spent 2 hours manually figuring out where the next entry point is, only to notice that the actual input was a different shape than the example one. I just gave up with the second star immediately after that.
Future improvement ideas
What's a retrospective if there's no improvement ideas and action items?
There's one big thing I'd like to find a solution for before next year: a way to show my progress through each puzzle. And preferably in a way that doesn't require the reader to go through git diffs. I think Amos is doing quite a nice series with Rust that I've been reading to learn Rust and to pick up inspiration for my explanations.
When a reader goes to my Advent of Code page and starts reading through the solutions, they are faced with the refactored, polished solution. And while that is okay, for the enhanced learning opportunities I'd like to find a way to show my code in different stages and explain the changes and how I ended up with those changes and why I think they improve the code.
Sign up for Syntax Error, a monthly newsletter that helps developers turn a stressful debugging situation into a joyful exploration.