Advent of Code is a seasonal series of daily programming puzzles that can be solved in any language you choose to use. People can enjoy taking part in this yearly event in many ways: as a speed contest, interview prep, company training, university coursework, practice problems, or to challenge each other. In 2021 I decided to give it a go for the first time, as I believe it's the kind of thing you can only understand by engaging with the event. I expected it to be difficult to keep up with the challenges every day, but I still wanted to take the opportunity to try out a new language. I'm familiar with Javascript so a good compromise was to reach out to Deno and that would implicitly force me to delve into Typescript.
With all its flaws, Javascript is the language of the web, the one that more closely represents how fast and loose the web goes by and how much people value that flexibility. However, everything has just one type in your JS code and that's where Typescript comes in. TS allows you to work with different types and then transpile your code into JS. That's all it does however, in the end, you're still working with Javascript and you can always sidestep the need to declare your types. But that's where Deno comes in, a Typescript runtime that is built in Rust and has a few attractive features:
With all its flaws, Javascript is the language of the web, the one that more closely represents how fast and loose the web goes by and how much people value that flexibility. However, everything has just one type in your JS code and that's where Typescript comes in. TS allows you to work with different types and then transpile your code into JS. That's all it does however, in the end, you're still working with Javascript and you can always sidestep the need to declare your types. But that's where Deno comes in, a Typescript runtime that is built in Rust and has a few attractive features:
- Secure by default. No file, network, or environment access, unless explicitly enabled.
- Ships only a single executable file.
- Has built-in utilities like a dependency inspector and a code formatter.
- Has a set of standard modules that are guaranteed to work with Deno.
I should also mention that in 2021 I started using Visual Studio Code (thanks to VSCodeVim) and Deno works very well with it, as does mostly anything that involves Typescript. That kind of integration with your code editor may be the most obvious advantage of having types in your Javascript. You are essentially taking errors that show up when your code runs and moving them pre-emptively to the context of your editor where they are easily found and fixed.
The trade-off is that, of course, you need to put more information about your code in a way that your editor can follow along. In this case, by defining types for your variables and describing how your objects are structured, you allow Deno's LSP (Language Server Protocol) to catch inconsistencies between what you expect of your variables and what you're doing with them. That's the thing with types, as with most things in programming: you think you need to do this because of the stupid computer, but it's actually for your benefit, you who will have to maintain this code. Much like good variable naming dispenses with a lot of comments, well-arranged types add implicit meaning to your code.
You can check out my 2021 Advent of Code in this repository. I knew that the puzzles would most likely lead me to stumble around my first attempts at Typescript as they're very much about working with large amounts of data until the correct answer falls out. But I also wanted to kick the tires of Deno itself, so I started working on this project before the Advent actually started. To save time getting myself going every day, I created a way to download each challenge that is published each day on the event's website. I had zero experience with the event, so I also expected to make a lot of adjustments to this workflow, which is fine. This gave me a reason to try out Deno's standard modules to do basic things like fetching files from the internet or managing some project folders.
My impressions of the event itself were positive, but I already had expectations that the difficulty curve would quickly increase and leave me behind. Everything was relatively new to me, which made it primarily a learning experience and not so much the thrill of solving puzzles. I also now understand the attraction that events like Advent of Code have for a lot of programmers: unlike most of what we do in our jobs, there is a definitive correct response for each problem and you can solve it in any way you like. I personally, on the other hand, kind of like the murkiness of delivering a solution that in real life is always not quite right and so we need to build upon it in feedback loops (as revealed by making a project out of the workflow itself). So I had no gripes with having it be about the journey just as much as ticking days on a calendar.
I recommend that Javascript folks give Deno a go and you can go through any of the previous editions of Advent of Code or wait until the next one. You can overcome the puzzles off-season, but there is a lot of motivation that can be gathered from joining the communities on Twitter, Reddit, or Discord. There are a lot of brilliant people out there.
(Originally written on April 24, 2022)