Esoteric Programming Languages and You!

by

Have you ever heard the term “esoteric programming language” and not known exactly what it was referring to? If so, this blog is for you, and hopefully an entertaining jaunt if not.

Esoteric programming languages are a unique class of programming languages that are generally NOT designed for everyday use on projects such as a website or phone app. Instead,
they are designed with a goal in mind, such as being a difficult as possible to program in, or to layout the code into a physical space that has meaning. Amusingly enough, even though they are often rather crazy, they also tend to be Turing complete which is quite impressive considering they weren’t necessarily designed with that goal in mind.

Why should I care?

As a software developer, you might be scratching your head at this point asking “If no one uses these languages in practice, why should I care about them?” I’m glad you asked!

Have you ever noticed that each language has somewhat of a mindset that you get into when working in it? Hopefully you have, if not try working in a wider variety of languages and you might notice it. The mindset shift tends to be most noticeable transitioning between functional and object oriented languages.

But I digress, that unique mindset is exactly why esoteric languages can be so useful. They teach you how to think in different ways to solve a problem, this means that even when you go back to a language you are well versed in, you are more likely to be open to solving a problem in a novel, better way that you might not have thought about before. They also can be fun “just because”. Sometimes they are a great way to blow off steam and reset after a partially challenging problem, so you could use them that way as well. That covers WHAT they are, but what about some examples? I’ve picked out a few esoteric languages so you can see some examples in action.

Befunge

The first we will be working in is a language called Befunge. This language treats the instructions as if the code is in a 2d space. This means the instruction pointer can move up, down, left, and right, so the same code can have different results depending on how the instruction pointer is moving. This also gets the fun instructions <^>v that change the direction that the instruction pointer moves. Here is a fairly simple program that outputs “Hi Grio”:

The program flow goes initially goes down, then sweeps to the right before looping back on itself to output data. You can see this in action on this nifty online interpreter. While that code works, it’s pretty boring. Because Befunge works on a 2d grid, we can instead turn our source code into a pretty ascii art source like this:

The most awesome thing about this is (other than some extra flow control instructions) all the operations are the same between the first code and this one! Here is an image to help illustrate how control flows through this code, since it is a lot harder to eyeball:

brainfuck

But what if you want a challenge because this code seems too easy to read? Meet brainfuck:

This can be run in this online interpreter. This language only has EIGHT! total instructions. Even more so than Befunge, this makes it really difficult to understand what it does just by looking at it. That code outputs “Hi Grio”, just like the prior Befunge code though. If you run it, you will notice it’s really slow. That’s because it was actually my first time writing code in brainfuck, so I decided I wanted to make it faster. Here is another program with the same output, but it runs about 4 times faster

Malbolge

Amusingly enough, for as ugly as Brainfuck code looks, it’s a surprisingly fun mental space to work in. But that’s no good, what if we want something that’s super hard to work in? A good choice for that would be, Malbolge. Named after the 8th circle of hell in Dante’s Inferno, it was specifically designed to be incredibly difficult to use. I didn’t even attempt to write an example of a working program on account of how difficult it is. Instead, I’m going to thank Andrew Cooke for writing this hello world program in it:

You can view his commentary about Malbolge on his website. In simple terms, Malbolge is crazy difficult, with unintuitive operations and self modifying code. Writing a program to output “Hi Grio” is left as an exercise for the reader.

whitespace

The final language I’m going to discuss is whitespace, which as it’s name implies, only uses whitespace characters. Here’s an example of a whitespace program:

Can you guess what this code does? I’ll let you try to figure it out rather than ruin the surprise.

Hopefully you now know more about esoteric programming languages and will be inspired to try working with one of the ones I covered, or any of the many others, in the future. Good luck and happy coding!

1 Comment

  1. Nate Powers on said:

    Great article! I definitely feel myself settling into different mindsets when working in Java vs JavaScript. But no mention of visual programming languages? ;) In all seriousness, I learned a little LOLCODE when I was first learning to program as a fun experiment, and coming back to JavaScript afterwards was like taking off a pair of heavy boots and putting on a pair of slippers. Soooooo much easier.

Leave a Reply

Your email address will not be published. Required fields are marked