Brainf*ck.

So, a little backstory of how I managed to discover this blasphemy. If you have ever taken any of Professor Mykhailo Medvediev’s lectures you are surely familiar with the self-graded coding system e-olymp.com where he usually gives tasks to his students to solve. That system offers a variety of different languages in which you could solve the given task. One day when I checked the options, it had Brainf#ck written there. Naive me thought that perhaps someone decided to hack the system and add this vulgarity to the list. But little did I know that in fact this obscene language actually exists, and moreover completely earns its name.
Software is an umbrella term for programs and libraries, which is essentially constructed of codes that tell the machinery what to do. There are plenty of languages in the world, each of them having a unique style, some of them showing similarities. Some of them are easy to understand even if you are not a coder yourself, well except this esoteric language called Brainfuck. It sure champions in the race of purposefully overcomplicated code.
History time:
Brainfuck was created in 1993 by a Swiss physics student named Urban Müller. The reason why he decided to create is that he wanted to attempt to create a language with the smallest possible compiler.
A compiler is a computer program that translates code written in a high-level programming language into something that can be understood by a machine.
The closer the language is to the computer’s instruction set (which essentially is translated into the binary) the less work needs to be done to translate it… by machine obviously. So, that was the main reason for Müller to create Brainfuck — so that he could create the smallest compiler.
Müller’s inspiration came from another painful programming language developed earlier that year by Wouter van Oortmerssen (a Dutch software engineer who in fact now works at Google) — FALSE. Oortmerssen still has a goal to create an “intentionally confusing” Turing-complete language with the smallest compiler. For comparison reasons, programming languages like C++ might run on a compiler that is around 2.6 Mb, FALSE’s compiler was only 1,024 bytes, roughly 2,600 times smaller.
The question may arise, why one would need a smaller compiler? The main advantage of a small compiler is less memory usage. Which leads to the language be more binary-looking and less easy-to-understand. And that was exactly the point: both programmers decided to create these esoteric languages as a challenge, not the utility.
In comparison with FALSE, Brainfuck’s compiler ended up being even smaller. Only 240 bytes and that’s due to the simplicity of the language. It consists of just eight commands: <, >, +, -, [, ], and ,. Even if it is considered simple language, it is surely one of the most confusing ones in the programming world. One simply needs to write a massive amount of code to execute a simple program.
Let’s show the example using our favorite and actually simple to understand language, Python. If you are willing to print the simple command “Hello, World!” you just need to type:

Now, to do the same thing in Brainfuck you will have to type (or better smash your head on keyboard randomly):

The easiest (yes, I know how ironic it sounds) way to think how this translates to “Hello, World!” is that certain groupings of commands map out to characters on the ASCII table, which assigns numerical values to standard characters such as letters of the alphabet.
The following explanations are taken from StackOverflow as I would not be able (even if tried) to explain it any better.
1. Basics
To understand Brainfuck you must imagine infinite array of cells initialized by 0
each.
...[0][0][0][0][0]...
When brainfuck program starts, it points to any cell.
...[0][0][*0*][0][0]...
If you move pointer right >
you are moving pointer from cell X to cell X+1
...[0][0][0][*0*][0]...
If you increase cell value +
you get:
...[0][0][0][*1*][0]...
If you increase cell value again +
you get:
...[0][0][0][*2*][0]...
If you decrease cell value -
you get:
...[0][0][0][*1*][0]...
If you move pointer left <
you are moving pointer from cell X to cell X-1
...[0][0][*0*][1][0]...
2. Input
To read character you use comma ,
. What it does is: Read character from standard input and write its decimal ASCII code to the actual cell.
Take a look at ASCII table. For example, decimal code of !
is 33
, while a
is 97
.
Well, lets imagine your BF program memory looks like:
...[0][0][*0*][0][0]...
Assuming standard input stands for a
, if you use comma ,
operator, what BF does is read a
decimal ASCII code 97
to memory:
...[0][0][*97*][0][0]...
You generally want to think that way, however the truth is a bit more complex. The truth is BF does not read a character but a byte (whatever that byte is).
3. Output
To print character you use dot .
What it does is: Assuming we treat actual cell value like decimal ASCII code, print corresponding character to standard output.
Well, lets imagine your BF program memory looks like:
...[0][0][*97*][0][0]...
If you use dot (.) operator now, what BF does is print:
a
Because a
decimal code in ASCII is 97
.
So for example BF program like this (97 pluses 2 dots):
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++..
Will increase value of the cell it points to up to 97 and print it out 2 times.
aa
4. Loops
In BF loop consists of loop begin [
and loop end ]
. You can think it's like while in C/C++ where the condition is actual cell value.
Take a look BF program below:
++[]
++
increments actual cell value twice:
...[0][0][*2*][0][0]...
And []
is like while(2) {}
, so it's infinite loop.
Let’s say we don’t want this loop to be infinite. We can do for example:
++[-]
So each time a loop loops it decrements actual cell value. Once actual cell value is 0
loop ends:
...[0][0][*2*][0][0]... loop starts
...[0][0][*1*][0][0]... after first iteration
...[0][0][*0*][0][0]... after second iteration (loop ends)
Let’s consider yet another example of finite loop:
++[>]
This example shows, we haven’t to finish loop at cell that loop started on:
...[0][0][*2*][0][0]... loop starts
...[0][0][2][*0*][0]... after first iteration (loop ends)
Even though, Brainfuck is esoteric and essentially confusing by design, it is still Turing-complete and theoretically can be used to solve any problem just like any other programming language. However, I would argue that to write similar code it may take more time with Brainfuck even though it will take less compilation time. So, a simple advice would be — don’t.
There also exists Bodyfuck, which is Brainfuck but in human movements. Confusing, right? If you got extra 7 minutes to waste, here’s a video of the creator of Bodyfuck, Nik Hanselmann, outputting “Hello, World!” for you.
And this concludes this short blog of weird programming languages. Hope you enjoyed reading this.
main source of reference, besides the mention hyperlinks:
Brainfuck: code that was designed to hurt