Elm – building a version of Snake in under 100 lines of code

It’s been a little while since I last spent time with Elm, and since Elm 0.13 was recently announced so what better time to get my Elm hat back on and see what’s new.

There’s a new-look online debugger which looks prettier than before:


but more important than that, is the new Elm Reactor command line tool which powers both the online debugger. With the Elm Reactor you can run your own time-travelling debugger locally and as you edit your Elm source files you can watch your application update in real-time while retaining the ability to go back in time by play back previous events.

There’s also a new command line package manager – Elm Get – which gives you the ability to easily add community Elm libraries to your project, or to publish your own libraries to the Elm Public Library. Overall it works very similar to the how Dart-pub works and whilst I haven’t published any libraries myself it seems a straight forward affair.

There are a couple of small breaking changes in the core language, and it’s great to see that F#’s functional composition operators (<< and >>) have been adopted and released in this version!


Now that I’ve caught up on the changes, I put together a simple implementation of Snake, and to my pleasant surprise the whole thing came in at less than 100 LOC although admittedly not the easiest 100 LOC I’ve ever written. I had to really think about what I’m doing (which is a good thing), the lack of IDE support occasionally gets in the way, and I find the error message hard to read sometimes (although it’s much better formatted when you work against Elm Reactor running locally.

If you’ve got a few minutes to kill, why not give it a go:


and feel free to check out the source code on Github.



Elm Reactor – Time Travel made Easy

Elm 0.13 – Architecture Improvements

Elm startup project

Elm-Snake project page

Enjoy what you’re reading? Subscribe to my newsletter and get more content on AWS and serverless technologies delivered straight to your inbox.

Yan Cui

I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.

You can contact me via Email, Twitter and LinkedIn.

Hire me.

Check out my new course, Complete Guide to AWS Step Functions.

In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices.

Get Your Copy