Eleanor Mollett

Eleanor Mollett

Learning to code with Advent of Code

It's that time of year again, when Advent of Code starts releasing daily puzzles.

I've been using Advent of Code to help me learn to code for the past 5 years now (right now I am procrastinating from doing it by writing this). The first year I did it I wasn't a real developer yet, just a delivery manager who wrote a bit of code. I had used things like codecademy and code wars initially but wanted some chunkier challenges. It was while working through it that I realised I enjoyed writing code so much more than my job at the time, and was persuaded to start working towards a career change.

Since then I've used it several times to help pick up a new language. I used C# the December after getting my first dev job as that was what we were using at work. Python the next year as it was something I wanted to try out as I was thinking of applying to new jobs. Ruby the next year as it was the language I was now using in my new job. This year I've returned to javascript to polish it back up as I haven't written much in it in a while.

I've found it useful for learning a few different things - getting more familiar with syntax, learning what built in features a language has, learning to use TDD properly, learning how to write in a more object orientated way (admitedly advent of code is not ideal for this), and general problem solving.

I like the stories behind each days puzzle, and find that comprehending what the actual problem I need to solve is from the description is a useful skill for real life software dev work. The daily release and knowing it's all over by the end of December keeps me going too.

My tips for using Advent of Code to learn how to code:

  • Don't worry about your speed. There are so many reasons other people manage it faster. For me, I did best speed wise when I was up at 5am feeding a newborn because I happened to be awake when the puzzle came out, and needed the distraction to keep me awake. Now I have work and a toddler so I haven't even finished day 1.

  • Write tests. It just makes your life easier. You might not feel as fast, but as soon as you hit a problem you'll go faster. The first one I did I sketched out my thoughts in comments and then wrote code with a lot of console logs as I didn't yet know how to write tests. It worked, but it got confusing. Writing a series of unit tests does the same thing - it lets you go a bit at a time and check what you're getting at each stage.

  • Don't worry about looking everything up. This depends on your aim. The first year I did it I wanted to become a person who knew all the syntax by heart so really beat myself up about looking things up. I thought that real developers just knew it fluently. Maybe some do, but I look everything up day to day anyway so I may as well look it all up for this.

  • Take a look at other peoples code if you get stuck! It's not cheating if you aren't competing, and looking at other peoples code helps you learn. I particularly like looking at peoples code in other languages to see how they did it, and if I can work out how to do that in mine.

  • Join a communities around it to help you. I use the redit forum, and the channel on the cross gov slack to see what other people are doing and as the days go on, share my frustrations. There are some brilliant attempts out there, while I'm always impressed by the speed the people competing for the main leaderboard manage, I'm always on the lookout for people doing it in something like excel and marvelling at their madness.

  • Join a local leaderboard. You are almost certainly never going to compete on the global leaderboard, and it is nice to see how people you know are getting on. I'm on one where I can see the name of a dev I worked with 6 years ago and it makes me smile to remember that team.

  • Give up when it isn't enjoyable. I've never got to the end. For a few years I tried getting more stars than the year before. Now I'm just happy if I get some done.

For more tips and details, have a read of Neil Vass' post on Advent of Code which goes in to a lot more detail and tips.