DEV Community

Tawhid
Tawhid

Posted on • Edited on

Brainfuck in a nutshell. (and Why Would You Want to Learn It)

So you know Python, JavaScript. and then some guy leaned over and said: "Brainfuck."
You laughed. You thought that it was a joke.
Well, it is true.

And yes the name is 100% intentional.

What is Brainfuck?

Brainfuck is a Turing-complete esoteric programming language created by Urban Müller in 1993.
It's as hard to use as humanly (and technically) possible yet still technically able to do anything any other language can do (with a lot of time, patience, and possibly a few tears).

It's not used to create websites or apps. It's more of a puzzle, a logic gym for brains.

How Does It Work?

If you have:

  • A line of memory cells that's very long (like a line of small boxes, all set at 0)

  • A pointer that moves left or right across these boxes

  • And 8 commands to interact with them

Symbol What it does
> Move pointer to right
< Move pointer to left
+ Increment current cell by 1
- Decrement current cell by 1
. Print the ASCII character at current cell
, Input a character; store it at current cell
[ If current cell is 0, jump past matching ]
] If current cell is not 0, jump to matching [

That's all. No functions, no variables, no comments. Pure, keyboard-bashing chaos.

Your First Brainfuck Program: Hello, World!

Here’s the classic "Hello, World!" in Brainfuck:

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Enter fullscreen mode Exit fullscreen mode

What does this do?
Uh… don’t ask.
But here's a breakdown of just the first part to give you a feel:

++++++++++        // set cell #0 to 10
[                 // start loop
 >+++++++         // move to cell #1, add 7
 >++++++++++      // move to cell #2, add 10
 >+++             // move to cell #3, add 3
 >+               // move to cell #4, add 1
 <<<<-            // move back to cell #0, subtract 1
]                 // loop until cell #0 is zero
Enter fullscreen mode Exit fullscreen mode

It's like attempting to eat soup with a screwdriver. Not intended for the purpose, but worth a look.

Why Learn Brainfuck?

Sincerely? You most likely won't require it. But here's why you might consider it:

  • Puzzle Addicts: Sudoku in Morse code. Aside from it could be your secret language ;-p
  • Brain Gymnastics: It gets you thinking bottom-up, like loops and memory from the ground up.
  • Wow Your Nerd Friends: Build a full program using only + and >, and others will wonder.
  • Get a Deeper Understanding of Computers: You'll get a sense of how computers really work at a far deeper level.

Try It Out (No Setup Required)

You may run Brainfuck code in your browser using one of the following:

  • copy.sh
  • Dcode.fr Brainfuck Interpreter

  • Or just Google “Brainfuck online interpreter”, they’re everywhere
    Paste in the Hello World example and hit run. Boom, you’re a Brainfuck developer now. And then add it on your LinkedIn resume!

Final Thoughts

Brainfuck is not about practicality.
It's simply a matter of flexing your brain, playing around with code, and chuckling at how silly things get.
If you are bored, curious, or just want to flex, give it a shot. You will not create the next monstrous app in it, but you will certainly get your low-level stripes.

Top comments (0)