Brainf#ck - The Programming Language

Brainf#ck - The Programming Language


3 min read

“How minimalistic can a programming language be?”. Can it be as minimalistic as Brainfuck, an esoteric (mysterious, hard to understand) programming language created in 1993? Its creator Urban Muller set out for its creation to implement the smallest possible compiler; he succeeded with a size of 296 bytes.

So, how does this esoteric programming language work?

Well, the language consists of 8 commands listed below:

The commands are executed sequentially; hence, the program is a sequence of these commands. The compiler or interpreter should disregard any character other than the eight specified above. Characters other than the eight operators should be considered comments. As the name implies, Brainfuck programs are sometimes tough to understand. It is essentially a Turing-complete language.

The idea behind Brainfuck is memory manipulation. Essentially, we are provided an array of 30,000 1-byte memory chunks. The array size is determined by the implementation used in the compiler or interpreter, although normal brainfuck is 30,000. Within this array, you may raise the memory pointer, the memory pointer's value, and so forth.

As roachhd mentions in his GitHub post: “When cavemen started scrawling shit on the walls, the first-ever picture drawn was a man waving at a picture of the planet Earth.” So why not look at “Hello World” through the eyes of Brainfuck :

Hello World













I'm sure this made you go

Here is a brief explanation:

The first line begins with a “>” followed by 8 “+” which implies moving one cell to the right and incrementing that cell’s value eight times. This gives us—you guessed it—the value 8 in cell 1. Following this is a “[“, then a “<” and a total of 9 “+” which is followed by a “>”, a “-” and a closing “]”. Thus, we begin a loop( [ ) in which we move left (<, back to cell 0), add nine (9+s) to that cell, move right again(>), and remove one from the number in cell 1. Remember that the loop runs until the cell value reaches zero, thus this would be repeated eight times, each time adding nine to cell 0. So we can see that cell 0 has a value of 72, corresponding to the capital letter 'H' in the ASCII table. The line is concluded by a “.” corresponding to the character “H” output.

memory blocks

A memory block visualization yields:




memory pointer

Similarly, in the second line, we added the ASCII value of 101, which represents “e”.

This way, we can interpret this language that is true to its name.

As can be understood, the language scores very low in its efficiency. However, it is still a cult classic among programmers of various age groups. Use at your own risk and get ready to be “Brainf#ck” -ed.

Did you find this article valuable?

Support GDSC NIT Silchar Blog by becoming a sponsor. Any amount is appreciated!