Just finished this year's Advent of Code.
https://adventofcode.com/
I already participated last year. Back then, my motivation was to learn
more about Rust. I got carried away in 2021, though: It is very tempting
to try to be competitive. So I quickly switched to Python in 2021. I
think that's a pretty great language for this kind of thing: It runs
fast (enough), it's very powerful, and easy to write.
This year, I really wanted to stick to Rust. So, first, no competition.
I left (almost) all private leaderboards.
Second, learning Rust shenanigans is hard enough -- solving the puzzles
on top of that can be too much for me. So I said to myself: If I really
get stuck, I won't spend hours trying to solve that puzzle and look for
help instead. (I still managed to solve all but three days on my own,
which isn't too bad, I guess.)
Honestly, I think looking for help makes for a better learning
experience. If you're truly stuck and have no idea how to solve a
particular problem, then you learn much more if you get a hint in the
right direction or maybe a full explanation. I mean, what's the
alternative? Suppose you don't know any path finding algorithm (and
maybe don't even know what to look for), then how will you solve that
puzzle involving a maze? I'd have to *reinvent*, say, Dijkstra's
algorithm -- completely unrealistic. Instead, if I look for help, then I
can learn: "Aha, that's how you solve this kind of problem." And next
time I can do better.
So, this year, it was all Rust.
I should have made a list, but here's what I remember:
- Learned about Rc/Weak and RefCell and how to represent graphs. Also
learned about the alternative "arena" implementation of that.
- Passing closures around as function pointers.
- Enums with attached data for representing linked lists.
- Implementing "Ord", so custom objects can be sorted.
- Basic multithreading.
- Looping over negative ranges ("for x in (width - 1)..=0" doesn't
work, but "for x in (0..width).rev()" does the trick).
- Breaking out of loops other than the innermost one. :-)
And of course, more experience in general with the language.
What I steared clear of:
- Using crates. Everything just uses the standard library.
- "Clever" or "functional" code (for the most part).
I guess my code is very "C-like". It's what I'm used to, it's how my
brain works. I cannot make peace with super-concise code that crams a
ton of meaning into just a few bytes. Some people love that -- I find it
very hard to read.
I'm still not sure if I really want to use Rust in my real-life
projects. I'm very ambivalent about this language. Still, with every
line of Rust code that I write, I understand it a little bit better, and
maybe, one day, I can form an informed opinion.
Merry Christmas.