Est. 1993 Advanced

Befunge

A two-dimensional esoteric programming language where code flows through a grid in multiple directions, designed to be as difficult to compile as possible.

Created by Chris Pressey

Paradigm Esoteric, Stack-based, Two-dimensional
Typing None (operates on integer stack)
First Appeared 1993
Latest Version Funge-98 (1998)

Befunge is a two-dimensional esoteric programming language created by Chris Pressey in 1993. Unlike traditional languages where code flows linearly from top to bottom, Befunge programs exist on a grid where execution can travel in any cardinal direction - right, left, up, or down.

History & Origins

Chris Pressey created Befunge in 1993 for the Amiga with a very specific goal in mind: to design a language that would be as difficult to compile as possible. The two-dimensional nature and self-modifying code capabilities make static analysis extremely challenging.

The Name “Befunge”

The word “Befunge” originated as a typo. During a late-night BBS chat session (around 4 AM), Curtis Coleman accidentally typed “Befunge” instead of “before.” Pressey encountered this typo and immediately decided it was the perfect name for a programming language he wanted to create.

Influence on Esoteric Languages

Befunge is believed to be the first two-dimensional, ASCII-based, general-purpose programming language. Its creation helped establish the “esolang” (esoteric language) community. The Befunge Mailing List, which Pressey started in 1995, eventually evolved into the Esoteric Topics Mailing List, helping to formalize the concept of esoteric programming languages.

How It Works

The Playfield

A Befunge-93 program exists on an 80x25 grid of ASCII characters called the “playfield.” Each cell contains a single instruction, and the program counter (called the “instruction pointer” or IP) navigates through this grid.

The grid is toroidal, meaning if the IP moves off one edge, it wraps around to the opposite edge - like a video game screen.

The Instruction Pointer

The IP starts at position (0,0) - the top-left corner - moving right. It continues in its current direction until it encounters a direction-changing instruction.

The Stack

Befunge uses a stack for data storage, similar to Forth. Most operations push values onto or pop values from this stack. The stack can hold arbitrary integers.

Commands

Befunge-93 has a compact instruction set:

Direction Commands

CommandDescription
>Move right
<Move left
^Move up
vMove down
?Move in a random direction

Math Operations

CommandDescription
+Addition: pop a and b, push a+b
-Subtraction: pop a and b, push b-a
*Multiplication: pop a and b, push a*b
/Division: pop a and b, push b/a
%Modulo: pop a and b, push b%a

Stack Operations

CommandDescription
0-9Push the digit onto the stack
:Duplicate top of stack
\Swap top two values
$Discard top of stack

Logic & Control

CommandDescription
!Logical NOT: pop value, push 1 if zero, else 0
`Greater than: pop a and b, push 1 if b>a, else 0
_Horizontal if: pop value, go right if zero, left if non-zero
``

Input/Output

CommandDescription
.Output top of stack as integer
,Output top of stack as ASCII character
&Input integer and push
~Input character and push ASCII value

String Mode

CommandDescription
"Toggle string mode: push ASCII values of characters until next "

Self-Modification

CommandDescription
gGet: pop y and x, push value at (x,y) in playfield
pPut: pop y, x, and v, write v to (x,y) in playfield

Control

CommandDescription
#Bridge: skip next cell
@End program
Space: no-op (do nothing)

Versions

Befunge-93

The original specification with:

  • Fixed 80x25 playfield
  • Limited to what can be expressed in this grid
  • Not technically Turing-complete due to finite memory

Funge-98

The extended specification (1998) that removes limitations:

  • Unlimited playfield size (making it Turing-complete)
  • Additional instructions
  • Support for higher dimensions (Unefunge-98 for 1D, Trefunge-98 for 3D)
  • Concurrent execution support

Why Befunge Matters

1. Compilation Challenge

Befunge’s explicit design goal of being “difficult to compile” makes it an interesting case study. The self-modifying code (via p command) means the program can rewrite itself during execution, making static analysis nearly impossible.

2. Spatial Programming

Befunge pioneered the concept of truly two-dimensional code. The visual layout of a Befunge program matters - you can often trace execution paths by following the direction arrows.

3. Esoteric Language Foundation

As one of the earliest and most influential esoteric languages, Befunge helped establish a community of language designers who create languages for artistic, educational, or humorous purposes rather than practical use.

File Extensions

Befunge source files typically use:

  • .bf - Common (shared with Brainfuck, so context matters)
  • .b93 - Befunge-93 specific
  • .b98 - Funge-98 specific
  • .befunge - Explicit

Running Befunge

Many interpreters exist:

  • befunge93 - Reference implementation
  • cfunge - Fast C implementation supporting both 93 and 98
  • PyFunge - Python implementation
  • BeQunge - Visual debugger for Befunge

For this tutorial, we use the esolang/befunge93 Docker image for consistent cross-platform execution.

A Word of Caution

Befunge is intentionally challenging. It’s designed for:

  • Exploring unusual programming paradigms
  • Compiler theory discussions
  • Programming challenges and puzzles
  • Having fun with constraints

It is not designed for:

  • Production code
  • Practical applications
  • Teaching beginners to program

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

Timeline

1993
Chris Pressey creates Befunge for the Amiga, explicitly designed to be difficult to compile
1993
Believed to be the first two-dimensional, ASCII-based, general-purpose programming language
1995
Pressey starts the Befunge Mailing List
1997
Befunge web page listed as 'Geek Site of the Day', causing surge in popularity
1998
Funge-98 specification released, extending the language with unlimited grid size and Turing completeness
Present
Numerous implementations exist; Befunge remains one of the most popular esoteric languages

Notable Uses & Legacy

Compiler Design Challenges

Used to explore the limits of compilation, as self-modifying code makes static analysis nearly impossible.

Code Golf

Popular in programming challenges due to its unique 2D nature and concise instruction set.

Esoteric Language Community

Foundational language that helped establish the 'esolang' community and inspired many other 2D languages.

Programming Puzzles

Used in CTF competitions and puzzle challenges for its unusual execution model.

Language Influence

Influenced By

Forth AmigaVision

Influenced

Wierd PATH Other 2D esoteric languages

Running Today

Run examples using the official Docker image:

docker pull esolang/befunge93

Example usage:

docker run --rm -v $(pwd):/code:ro esolang/befunge93 befunge93 /code/hello.bf

Topics Covered

Last updated: