Whitespace is an esoteric programming language created in 2002 by Edwin Brady and Chris Morris at the University of Durham, notable for using only whitespace characters—space (ASCII 32), tab (ASCII 9), and line feed (ASCII 10)—as its syntax, while treating all other characters as comments. This is the inverse of most programming languages, which largely ignore whitespace characters.
History
Brady and Morris developed Whitespace in 2002, and it was reviewed on Slashdot on April Fool's Day 2003. The idea of using whitespace characters as operators had been facetiously suggested five years earlier by Bjarne Stroustrup for the C++ language. Both creators also developed the Kaya and Idris languages.
Syntax
Whitespace is an imperative, stack-based language. A command consists of a sequence of whitespace characters structured as an Instruction Modification Parameter (IMP) followed by an operation and any parameters.
IMP sequences:
| IMP | Meaning |
|---|---|
| [Space] | Stack Manipulation |
| [Tab][Space] | Arithmetic |
| [Tab][Tab] | Heap Access |
| [LineFeed] | Flow Control |
| [Tab][LineFeed] | I/O |
Operations include stack push, duplicate, swap, and discard; arithmetic (addition, subtraction, multiplication, integer division, modulo); heap storage and retrieval; flow control (labels, subroutines, conditional jumps); and I/O (output character/number, input character/number).
Numbers are represented as a sequence of space (binary 0) and tab (binary 1) characters terminated by a line feed. The first character indicates sign: space for positive, tab for negative.
Labels are linefeed-terminated sequences of space and tab characters. All labels must be unique within a program as there is only one namespace.
Comments: Any character other than space, tab, or linefeed is ignored and can be used for comments. This property allows Whitespace source code to be embedded within the whitespace of code written in other languages, making the file a polyglot.
Sample Code
A "Hello, world!" program in Whitespace (annotated with S for space, T for tab, L for linefeed):
S S S T S S T S S S L Push 72 ('H')
T L Output 'H'
S S S T T S S T S T L Push 101 ('e')
T L Output 'e'
... (continues for each character)
L L L End the program
Example "Hello, world!" in plain whitespace
When rendered visibly, a simple Whitespace program that prints "Hello, world!" appears as invisible characters. The following is a visual representation (brackets indicate the actual whitespace characters):
[space][space][space][tab][space][space][tab][space][space][space][linefeed]
[tab][linefeed]
[space][space]
Reception and Legacy
Whitespace is categorized as an esoteric programming language—a language designed as a proof of concept or for humor rather than practical use. It has inspired numerous implementations, interpreters, and compilers across many programming languages. A collection of interpreters, compilers, and programs is maintained at the Whitespace Corpus on GitHub.