Using Roc for Advent of Code
Tags: #review

Knock, Knock! Advent of Code is here! It is a yearly event starting from December 1st to December 25th. Each day you're given a puzzle to solve. These puzzles contain two parts, the second part builds on top of the first one and is a bit more complex. More info here.

This year, I decided to spice things up a bit and teamed up with a friend to solve each day in a different programming language. For day two, we used Roc and this is my thoughts on it.

What is Roc?

Roc is a pure functional programming language. I have to mention this, functional languages always scared me a bit. They all seem so different than the languages we usually use. However, you'll see that Roc promotes itself as a friendly language. And they weren't lying. Even for someone who never touched functional programming languages before, Roc was fairly simple to write code for. While I was intimidated, I eventually figured it out. Just.. took 10+ hours of mindless reading and writing code.

Experience with Roc

You can actually try out Roc without installing via their online REPL (read-eval-print-loop), which is on their homepage. Installing Roc is pretty straightforward, check the install page.

Getting used to writing Roc code was a struggle, I won't deny. I was making mistakes left and right at the beginning with my confused brain. I was trying to apply non-functional practices and it obviously didn't work out and I "wasted" a lot of time. I put wasted in quotes since I technically learned a lot about functional programming in general but still, I'm angry.

I'll give credit to Roc's documentation though, it's really good and Roc itself is a pretty simple language. I don't think I would've learnt Haskell in just 10 hours. It's not like I understand Roc that well, but I was able to solve AoC with it, which I consider to be a great accomplishment in this case.

Roc's community chat is pretty active. The people there are extremely nice and kind. They have an active Advent of Code communinity too. They also really seem to care about developer experience, and are thriving to make the language better. I definitely recommend you to join their chat if you're trying out Roc.

Since, Roc is still in early development, it's obvious that it's gonna have some rough edges. One of my issues with Roc was that I wasn't able to grasp the error messages properly, so I had to take some help from the peeps at Roc's chat.

Documentation is what really makes Roc stand out in my opinion, to be honest. And on top of that, having a responsive community also helps. While I went into this thinking I'm going to have a terrible time (which I did for the most part, lol) with it, but at the end, it wasn't too bad. After I understood the language and functional programming a bit more, it took me only around 1 hour to finish the puzzle. Here's my code.

I also tried to use Roc's LSP server. While it took a while to build, in my opinion it wasn't worth it at all. It provides very little functionality and just didn't work well for some reason. Maybe I messed something up, don't know for sure. But at the end I decided I don't need it, and just ditched it.

The examples provided in Roc's git repo are interesting. It seems like you can do a lot more with this language than what I had originally imagined.

Overall, Roc is a pretty simple (doesn't necessarily mean easy) language, and you can do a lot with it. Maybe try it yourself, AoC is still going on at the time of writing ;) More importantly, don't give up.

If you have any feedback, feel free to comment below or send me an email on: Until next time!