Est. 1993 Advanced

Brainfuck

A minimalist esoteric programming language with only 8 commands, designed to challenge and amuse programmers while being Turing-complete.

Created by Urban Muller

Paradigm Esoteric, Imperative
Typing None (operates on byte cells)
First Appeared 1993
Latest Version N/A (specification unchanged since creation)

Brainfuck is perhaps the most famous esoteric programming language ever created. With only eight simple commands and a minimalist design philosophy, it proves that a programming language doesn’t need to be practical to be Turing-complete and wildly influential.

History & Origins

In 1993, Swiss physics student Urban Muller set out to create a programming language with the smallest possible compiler. Working on the Amiga platform, he succeeded spectacularly - the original Brainfuck compiler was only 240 bytes, later reduced to under 200 bytes by other implementations.

The name, while crude, perfectly captures the language’s essence: it’s designed to confuse and challenge programmers while remaining technically capable of any computation a conventional language can perform.

Why “Brainfuck”?

The provocative name serves multiple purposes:

  • It accurately describes the mental experience of programming in it
  • It reflects the language’s countercultural, hacker origins
  • It ensures the language is memorable (for better or worse)

Many sanitized versions exist: “Brainf*ck”, “BF”, “Brainfsck”, etc. The language has also inspired numerous variants with different themes: Ook! (uses orangutan sounds), Spoon (uses only 0 and 1), and Chef (programs look like recipes).

The Eight Commands

Brainfuck operates on an array of memory cells (traditionally 30,000 bytes), each initially set to zero, and a pointer that starts at the first cell:

CommandDescription
>Move the pointer right one cell
<Move the pointer left one cell
+Increment the value at the pointer
-Decrement the value at the pointer
.Output the byte at the pointer as ASCII
,Input a byte and store it at the pointer
[Jump forward past matching ] if value is zero
]Jump back to matching [ if value is non-zero

All other characters are ignored (treated as comments).

Why Brainfuck Matters

Despite being intentionally impractical, Brainfuck has made genuine contributions:

1. Theoretical Computer Science

Brainfuck is Turing-complete, meaning it can compute anything that any other programming language can compute. This makes it a valuable tool for exploring the minimal requirements for universal computation.

2. Compiler Education

Writing a Brainfuck interpreter is often a first exercise in compiler courses. The simplicity of the language makes the parsing and execution logic straightforward to implement and understand.

3. The Esoteric Language Movement

Brainfuck essentially created the “esolang” (esoteric language) community. Hundreds of languages have been created since, each exploring different aspects of what makes a programming language.

4. Optimization Challenges

Optimizing Brainfuck programs is a fascinating puzzle. Techniques like run-length encoding, loop unrolling, and pattern recognition are commonly applied.

Programming Concepts in Brainfuck

Despite its simplicity, Brainfuck requires understanding several concepts:

Memory Management

You must manually track which cells contain what data and navigate between them:

1
2
>>>>>  Move 5 cells right
<<     Move 2 cells left (now at cell 3)

Loops

The [ and ] brackets create while loops:

1
[->+<]  While cell is non-zero: decrement it, move right, increment that cell, move back

This pattern copies a value from one cell to another.

Arithmetic

Addition and subtraction are straightforward, but multiplication requires loops:

1
2
+++      Set cell to 3
[>++<-]  Multiply by 2: result in next cell (6)

File Extensions

Brainfuck source files typically use:

  • .bf - Most common
  • .b - Short form
  • .brainfuck - Explicit

Running Brainfuck

Many interpreters and compilers exist:

  • beef - Fast interpreter with debugging
  • bfc - Compiles to native code
  • Various online interpreters - Great for quick experimentation

For this tutorial, we use a Docker-based interpreter for consistent cross-platform execution.

A Word of Caution

Brainfuck is intentionally difficult. It’s meant for:

  • Learning about computation theory
  • Programming challenges and puzzles
  • Demonstrating Turing completeness
  • Having fun with constraints

It is not meant for:

  • Production code
  • Practical applications
  • Teaching beginners to program

Continue to the Hello World tutorial to write your first Brainfuck program.

Timeline

1993
Urban Muller creates Brainfuck with a 240-byte compiler
1993
Released to Amiga community, gains cult following
1998
Inspires Malbolge, an even more difficult esoteric language
2000s
Becomes the most well-known esoteric programming language
2003
Whitespace created, inspired by Brainfuck's minimalism
Present
Remains popular for code golf, education, and programming challenges

Notable Uses & Legacy

Compiler Design Education

Used to teach compiler and interpreter construction due to its simple specification.

Code Golf

Popular in competitive programming challenges where code length matters.

Turing Machine Demonstrations

Proves that minimal instruction sets can achieve universal computation.

Obfuscation Challenges

Used in CTF competitions and puzzle challenges for its readability (or lack thereof).

Language Influence

Influenced By

P'' (Corrado Bohm) FALSE

Influenced

Ook! Whitespace Malbolge Many other esoteric languages

Running Today

Run examples using the official Docker image:

docker pull sergiomtzlosa/brainfuck:latest

Example usage:

docker run --rm -v $(pwd):/code sergiomtzlosa/brainfuck /root/brainfuck/brainfuck /code/hello.bf

Topics Covered

Last updated: