Whitespace
An esoteric programming language where only whitespace characters (space, tab, and linefeed) are significant, while all other characters are ignored as comments.
Created by Edwin Brady, Chris Morris
Whitespace is an esoteric programming language created in 2003 by Edwin Brady and Chris Morris at the University of Durham. Its unique characteristic is that only whitespace characters—spaces, tabs, and linefeeds—are meaningful. All other characters are completely ignored, treated as comments.
History & Origins
Whitespace was released on April 1st, 2003, and announced on Slashdot. Most readers assumed it was an April Fool’s joke, but the language was (and is) completely real and functional. The timing was deliberate—what better day to release a language that inverts the normal rules of programming?
The Creators
Edwin Brady and Chris Morris, both at the University of Durham, created Whitespace. Brady is perhaps better known for creating the Idris programming language, a dependently-typed functional language. The same mind that gave us cutting-edge type theory also gave us a language of invisible instructions.
Why Whitespace?
The language is a commentary on how most programming languages treat whitespace: as insignificant formatting that helps humans read code. Whitespace flips this convention entirely—the characters humans can see are meaningless, and the invisible characters carry all the meaning.
How It Works
The Three Characters
Whitespace uses exactly three characters:
| Character | ASCII Code | Common Notation |
|---|---|---|
| Space | 32 | [Space] or S |
| Tab | 9 | [Tab] or T |
| Line Feed | 10 | [LF] or L |
Everything else in a Whitespace program is ignored.
Stack-Based Architecture
Like Forth and Brainfuck, Whitespace is stack-based. It operates on a stack of arbitrary-precision integers, meaning there’s no limit to how large numbers can grow (within memory constraints).
The language also provides a heap for random-access storage, making it more powerful than pure stack-based languages.
Instruction Modification Parameter (IMP)
Instructions in Whitespace begin with an Instruction Modification Parameter (IMP) that determines the category of the operation:
| IMP | Category |
|---|---|
[Space] | Stack Manipulation |
[Tab][Space] | Arithmetic |
[Tab][Tab] | Heap Access |
[Tab][LF] | I/O |
[LF] | Flow Control |
Commands
Stack Manipulation (IMP: [Space])
| Command | Parameters | Description |
|---|---|---|
[Space] | Number | Push the number onto the stack |
[LF][Space] | - | Duplicate the top of stack |
[Tab][Space] | Number | Copy the nth item to the top |
[LF][Tab] | - | Swap the top two items |
[Tab][LF] | Number | Slide n items off the stack, keeping the top |
[LF][LF] | - | Discard the top of stack |
Arithmetic (IMP: [Tab][Space])
| Command | Description |
|---|---|
[Space][Space] | Addition |
[Space][Tab] | Subtraction |
[Space][LF] | Multiplication |
[Tab][Space] | Integer Division |
[Tab][Tab] | Modulo |
Heap Access (IMP: [Tab][Tab])
| Command | Description |
|---|---|
[Space] | Store: pop value and address, store value at address |
[Tab] | Retrieve: pop address, push value at that address |
I/O (IMP: [Tab][LF])
| Command | Description |
|---|---|
[Space][Space] | Output the top of stack as a character |
[Space][Tab] | Output the top of stack as a number |
[Tab][Space] | Read a character, store at address on stack top |
[Tab][Tab] | Read a number, store at address on stack top |
Flow Control (IMP: [LF])
| Command | Parameters | Description |
|---|---|---|
[Space][Space] | Label | Mark a location in the program |
[Space][Tab] | Label | Call a subroutine |
[Space][LF] | Label | Jump unconditionally to a label |
[Tab][Space] | Label | Jump to label if top of stack is zero |
[Tab][Tab] | Label | Jump to label if top of stack is negative |
[Tab][LF] | - | Return from subroutine |
[LF][LF] | - | End the program |
Number Encoding
Numbers are encoded in binary using space for 0 and tab for 1, prefixed with a sign bit (space for positive, tab for negative) and terminated by a line feed.
For example, to push the number 72 (ASCII ‘H’):
- Sign:
[Space](positive) - Binary:
[Tab][Space][Space][Tab][Space][Space][Space](1001000 = 72) - Terminator:
[LF]
Label Encoding
Labels are encoded similarly to numbers but without a sign bit—just a sequence of spaces and tabs terminated by a line feed.
The Polyglot Potential
Because all visible characters are ignored, a Whitespace program can be embedded invisibly within:
- Other programming language source code
- Plain text documents
- HTML/CSS files
- Any text file with significant whitespace
This makes Whitespace popular for:
- Steganography: Hiding programs in plain sight
- Polyglots: Programs valid in multiple languages
- Obfuscation challenges: Where finding the hidden program is part of the puzzle
File Extensions
Whitespace source files typically use:
.ws- Most common.wspace- Alternative.whitespace- Explicit
Running Whitespace
Various interpreters exist:
- Haskell reference implementation - The original
- Python implementations - Many available on GitHub
- C implementations - For speed
- Online interpreters - For experimentation
For this tutorial, we use the esolang/whitespace Docker image for consistent cross-platform execution.
Viewing Whitespace Code
Since the code is invisible, you need special tools to work with it:
- Hex editor: Shows the actual bytes (0x20, 0x09, 0x0A)
- cat -A (Unix): Shows tabs as
^Iand marks line endings - od -c: Shows all characters including whitespace
- Syntax highlighters: Some editors have Whitespace modes that colorize the invisible characters
A Word of Caution
Whitespace is intentionally unusual. It’s designed for:
- Exploring the concept of significant whitespace
- Steganography and polyglot programming
- Programming challenges and puzzles
- Having fun with conventions
It is not designed for:
- Production code
- Practical applications
- Teaching beginners to program
Continue to the Hello World tutorial to write your first (invisible) Whitespace program.
Timeline
Notable Uses & Legacy
Steganography
Embedding invisible programs within other text files or source code, since non-whitespace characters are ignored.
Polyglot Programming
Creating programs that are valid in multiple languages, with the Whitespace code hidden in the whitespace of other programs.
Programming Challenges
Used in CTF competitions and puzzle challenges due to its invisible nature.
Compiler/Interpreter Education
Writing a Whitespace interpreter is a common exercise for learning about parsing and stack machines.
Language Influence
Influenced By
Influenced
Running Today
Run examples using the official Docker image:
docker pull esolang/whitespaceExample usage:
docker run --rm -v $(pwd):/code:ro esolang/whitespace whitespace /code/hello.ws