Esoteric Programming Languages: Brainfuck

In early February, Stack Overflow data scientist Julia Silge published an article titled “What Programming Languages Are Used Most on Weekends?”. The data used to deduce what’s hot and what’s not among our fellow nerds during the weekend, is what tags are used on Stack Overflow questions.

Haskell, a function programming language, saw most questions during the weekend. Now, a high number of questions on Stack Overflow doesn’t necessarily mean that a language is immensely popular. It might just mean that Haskell programmers are dumb. Oh, I kid, I kid. I’m sure Haskell programmers are quite intelligent - and I’m hoping they have a sense of humor.

Anyway. What the data from Stack Overflow do show, is that programmers are focusing on very different things during our workweek than we do during the weekend. While a workweek is filed with cringe worthy topics like SharePoint, TSQL, and (gasp!) VBA, the weekend tend to be for experimenting with new things.

Let’s have a brief look at an esoteric programming language that might be of interest for your next weekend of experimenting: Brainfuck.

Brainfuck basics

Brainfuck is the creation of Urban Müller, who introduced the language back in 1993. As the name suggests, it’s not totally trivial to understand. Brainfuck has a total of 8 commends, each of which consists of a single character1:

CharacterMeaning
>increment the data pointer (to point to the next cell to the right)
`<decrement the data pointer (to point to the next cell to the left).
+increment (increase by one) the byte at the data pointer.
-decrement (decrease by one) the byte at the data pointer.
.output the byte at the data pointer.
,accept one byte of input, storing its value in the byte at the data pointer.
[if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, title=“Branch (computer science)">jump it forward to the command after the matching ] command.
]if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command.

Brainfucked by example

Creating a small program that outputs “Hello World!” is a common way to create a simple example that explains the basics of a programming language. Here’s such an example written in Brainfuck:

++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

And you thought badly written Java code was a bitch, eh? Brainfuck’s version of “Hello World!” might look like a mess, but the language is Turing-complete, which means that it is “capable of computing any computable function or simulating any other computational model, if given access to an unlimited amount of memory.”

But all that is theoretical. Writing anything in Brainfuck isn’t really practical, and learning the language probably won’t land you a job. Having the word “fuck” in any form on your resume doesn’t sound like a brilliant idea, either. But as a weekend brain exercise, it’s awesome. What about writing a JavaScript to Brainfuck converter?

That said, JavaScript doesn’t need the help of Brainfuck to totally melt your frontal lobe. JSFuck is a great example of that.

Bonus brainfuck

If you’re looking to be properly brainfucked, I recommend that you go ahead and watch the 2004 movie Primer. It’s about four aspiring entrepreneurs who accidentally builds a time machine, and the rather confusing events that follow. Many great minds have tried to explain Primer, but I’m still thoroughly confused. Randall Munroe of XKCD fame is probably the one who comes closest to explaining the movie in a way I understand.


  1. The table is shameless copypasta from Wikipedia↩︎


Feedback

This post has no feedback yet.

Do you have any thoughts you want to share? A question, maybe? Or is something in this post just plainly wrong? Then please send an e-mail to vegard at vegard dot net with your input. You can also use any of the other points of contact listed on the About page.


Caution

It looks like you're using Google's Chrome browser, which records everything you do on the internet. Personally identifiable and sensitive information about you is then sold to the highest bidder, making you a part of surveillance capitalism.

The Contra Chrome comic explains why this is bad, and why you should use another browser.