Esoteric Language Basics

The Whitespace Language Explained

Whitespace is an esoteric language whose programs use only spaces, tabs and line feeds. Learn how it works and what that means for reading and editing code.

On this page
  1. The core idea
  2. Ignored characters become comments
  3. How a program is structured
  4. What this means for reading code
  5. Is it practical?
  6. What it teaches about readable code

The core idea

Whitespace is an esoteric language whose source code uses only three characters: space, tab and line feed. Every other character is ignored by the interpreter. That makes a Whitespace program look like blank paper, and it turns a normally unimportant part of text files into the entire language.

The idea works as a clever inversion. Most languages treat whitespace as optional spacing between meaningful symbols. Whitespace makes the spacing the only meaningful thing.

Ignored characters become comments

Because anything other than the three significant characters is skipped, you can write ordinary visible text in a file and the interpreter will not care. This is how documentation is usually written in the language. A file can contain a readable description plus a hidden program, or the program can sit inside the gaps of printed text. The visible words are effectively comments, though they may have to avoid the three significant characters or else they would become part of the code.

This has an odd consequence: a Whitespace program can be embedded in a file that looks like something else entirely, and it is also easy to damage by accident.

How a program is structured

Programs are made of instructions, and each instruction begins with a short prefix that selects a group. The groups usually described are:

  • stack manipulation
  • arithmetic
  • heap access
  • flow control
  • input and output

After the prefix comes the specific operation, and some operations take a number. Numbers are written in binary, using one of the characters for zero and another for one, and ended with a line feed. A leading symbol typically marks the sign. The exact assignment of which character stands for which digit comes from the language specification, so check it before writing a program by hand.

The machine behind the language has a stack for working values and a heap for numbered storage locations. Programs use a stack-oriented style, much like the one in stack machines generally: push values, apply an operation, then output the result. Flow control uses labels, which are also sequences of whitespace characters, so loops and conditionals are possible.

What this means for reading code

Reading Whitespace is difficult in an unusual way. Most hard-to-read languages are dense with symbols, but Whitespace has the opposite problem, because you cannot see anything. A few practical consequences:

  • Normal editors hide the code. Without a setting that shows invisible characters, a file seems empty.
  • Small errors are invisible. A stray space or a tab converted to spaces by an editor can change the meaning of a program or break it altogether.
  • Version control and copy-paste are risky. Tools that trim trailing whitespace may quietly delete part of the program. Tools that convert tabs to spaces can do the same.
  • Debugging needs support. Many people write or use a tool that translates the program into readable mnemonics, such as “push”, “add” and “print”, and back again.

This last point shows a common pattern in odd languages: the real workflow often involves a friendlier representation that gets converted into the strange one.

Is it practical?

Not really, and it is not meant to be. Whitespace is better thought of as a thought experiment, and a Turing complete language in principle, given enough memory. It asks what happens if you strip away every visual cue. The answer is that you lose the ability to scan, search and review code with your eyes, which are things we rely on far more than we usually notice.

What it teaches about readable code

Whitespace makes clear that readability is a property of how humans see text, not of the language alone. Layout, indentation and visible punctuation carry a lot of meaning in ordinary programs. In most languages, whitespace is a cue for people, even if the compiler ignores it. In Whitespace the cue becomes the code, and the result is a text that no human can read without help.

If you try it, use an interpreter or assembler that shows the program in a readable form, and write small programs first: push a number, print it, and stop. Even that takes careful counting, which is a good illustration of how much effort a language can require when it removes the usual signposts.

The complete guide to esoteric language basics

What Are Esoteric Programming Languages?
Read the guide

Keep exploring

Guides from other topics

All topics →