Introducing Bitsy: The First Language You’ll Implement Yourself

August 15, 2016 / Ben DiFrancesco

TL;DR Implementing a programming language isn’t magic! Check out Bitsy if you want to start learning how! Also take a look at bitsy-swift, a simple Bitsy compiler built in Swift.

For the average user, smartphones and computers are black boxes, the inner workings of which are magical and intimidating. We— programmers— are the supposed magicians who know these dark arts. Sadly, most of us just push the mystification down a few levels. We know how to build apps! And websites! Below our slice of the stack? Oh, it’s black magic all the way down.

Here’s a secret: nothing is magic. It's not even as hard as we think.

Abstractions don’t exist to protect poor muggles from the impenetrable wizardry below. Abstractions exist because the layer below stopped scaling to the problems that needed solving.

Take assembly, for example. Impossible! Incomprehensible! Actually it’s pretty straightforward. Do you know how to program? Then you could learn assembly. It’s different and it’s tedious… but it's not magic. It just stopped being enough to write the kinds of programs people wanted to write without major headaches.

To solve this, programmers of yore dreamt up higher level languages and implemented them with compilers and interpreters, which, by the way, turns out to be just about as complicated of a program as you’d want to write in assembly. But you don’t have to build them in assembly or even C/C++ for that matter. You can write a new language in whatever language you know now!

If there is something impenetrable around the lower levels of the stack it's the resources out there for learning about them. They’re often theoretical and opaque, rather than practical or approachable. That’s a shame, because learning about the lower levels can make you a better developer, and it's also just plain fun!

A number of months ago I set out to learn about building a compiler. It’s been an on and off hobby project, and the learning has been slow at times. I’m still far from an expert, but I’ve gotten somewhere and it’s been fun, so I figured I pause for a second and make the path a little easier for the next person down.

Bitsy is a programming language with an unusual goal: it aims to be the best language to target when building your first compiler or interpreter. BitsySpec is a set of tests, and a command line utility for running them, that lets you know how your implementation is coming along. Point BitsySpec at your implementation and you’ll know what’s working and what's not. You can TDD your first compiler!

There’s one implementation of Bitsy so far: bitsy-swift. I’m hoping one day there will be many of them, along with resources and tutorials for every language community. Will yours be next?

Note: I’ll be speaking about building a Bitsy compiler in Swift at 360iDev and Indie DevStock. If you’re attending either, be sure to say hello!