Hello World in Whitespace
Your first Whitespace program - the classic Hello World example with Docker setup
Writing “Hello, World!” in Whitespace gives you a taste of programming with invisible characters. The code you’ll write consists entirely of spaces, tabs, and linefeeds—nothing else matters.
The Code
Create a file named hello.ws:
Yes, that’s the actual program! It looks blank (or nearly blank) because it consists only of whitespace characters. The file is 195 bytes of spaces, tabs, and linefeeds.
Understanding the Code
Since whitespace is invisible, we need an annotated version to understand what’s happening. Here’s the same program with S (Space), T (Tab), and L (Linefeed) notation:
| |
Breaking It Down
Each character in “Hello, World!” requires two operations:
- Push the ASCII value onto the stack
- Output it as a character
The Push Instruction
| |
The number encoding:
- First character is the sign: Space = positive, Tab = negative
- Following characters are binary digits: Space = 0, Tab = 1
- Linefeed terminates the number
For ‘H’ (ASCII 72 = binary 1001000):
- Sign:
S(positive) - Binary:
T S S T S S S(1001000) - Terminator:
L
The Output Instruction
| |
This pops the top of the stack and outputs it as an ASCII character.
The End Instruction
| |
ASCII Values Reference
| Character | Decimal | Binary | Whitespace (S=0, T=1) |
|---|---|---|---|
| H | 72 | 1001000 | TSSTSSS |
| e | 101 | 1100101 | TTSSTS T |
| l | 108 | 1101100 | TTSTTSS |
| o | 111 | 1101111 | TTSTTTT |
| , | 44 | 101100 | TSTTSS |
| (space) | 32 | 100000 | TSSSSS |
| W | 87 | 1010111 | TSTSTTT |
| r | 114 | 1110010 | TTTSSTS |
| d | 100 | 1100100 | TTSSTS S |
| ! | 33 | 100001 | TSSSST |
Creating the File
The tricky part is creating a file with exact whitespace characters. Here are several methods:
Method 1: Download from Repository
The easiest approach is to copy an existing hello.ws file from a Whitespace examples repository.
Method 2: Use a Script
Create the file programmatically with Python:
| |
Method 3: Hex Editor
Create a file with these exact bytes:
20= Space09= Tab0A= Linefeed
Running with Docker
The easiest way to run Whitespace without installing an interpreter locally:
| |
Expected Output
Hello, World!
Viewing the Actual Code
Since the code is invisible, you can verify it with various tools:
Show whitespace characters (Unix/macOS)
| |
Validate the structure
Each character in the output requires approximately 15 bytes of whitespace:
- 2 bytes for push IMP + command
- ~8-9 bytes for the number encoding
- 4 bytes for output command
Plus 3 bytes for the end instruction.
Why Whitespace Is Interesting
Steganography
Because non-whitespace characters are ignored, you can hide a Whitespace program inside any text file. For example, you could write a Python program with carefully placed spaces and tabs that also runs as a Whitespace program!
Polyglot Programs
A file can be valid in multiple languages:
- The visible characters could be valid Python
- The invisible whitespace could be valid Whitespace
- Both programs would run correctly in their respective interpreters
Editor Challenges
Most text editors:
- Trim trailing whitespace automatically
- Convert tabs to spaces (or vice versa)
- Normalize line endings
All of these will break a Whitespace program. You need an editor configured to preserve exact whitespace.
Common Pitfalls
Editor “helpful” features: Disable auto-formatting, trailing whitespace removal, and tab-to-space conversion
Line ending normalization: Different systems use different line endings (LF vs CRLF). Whitespace specifically uses LF (ASCII 10).
Copy/paste corruption: Copying from web pages often mangles whitespace characters
File encoding: Ensure UTF-8 or ASCII encoding without BOM
Historical Note
Edwin Brady and Chris Morris created Whitespace in 2003 at the University of Durham. They released it on April 1st, leading most people to assume it was an April Fool’s joke. It wasn’t—it’s a fully functional, Turing-complete programming language that continues to be implemented and used for programming challenges and steganography experiments.
Brady later went on to create Idris, a sophisticated dependently-typed programming language—quite a contrast from Whitespace’s invisible simplicity.
Next Steps
Try these modifications:
- Change the message to print your name
- Add a newline at the end (push 10, output character)
- Create a program that takes input and echoes it back
- Try embedding a Whitespace program inside another language’s source code
Running Today
All examples can be run using Docker:
docker pull esolang/whitespace