Befunge, short for Befunge-93, was created in 1993 by Chris Pressey. Befunge is an esoteric, two-dimensional, stack-based programming language where code is arranged on a grid and the instruction pointer can move in multiple directions. It is primarily used for experimentation, education, and exploring unconventional programming paradigms. Developers can access Befunge via implementations such as the official Befunge Interpreter, which provides executables and source code for Windows, macOS, and Linux.
Befunge exists to explore alternative approaches to program control flow and computation, emphasizing nonlinearity, creativity, and challenge. Its design philosophy embraces multi-dimensional instruction flow, stack-based computation, and self-modifying code. By allowing the instruction pointer to move in multiple directions and manipulate the code grid, Befunge solves the “problem” of exploring unconventional, esoteric language structures that encourage lateral thinking and puzzle-like programming.
Befunge: Stack and Arithmetic
Befunge operates on a stack, where numbers and characters are pushed and popped for computation. Arithmetic is performed using symbols and stack manipulation.
>987v
v456<
>123^
@The code above moves the instruction pointer through the grid, performing operations based on the symbols encountered. Numbers are pushed to the stack, and arithmetic instructions modify the stack contents. This approach is conceptually similar to stack-based languages like Forth or the stack operations in INTERCAL.
Befunge: Direction and Flow Control
Befunge uses directional commands (>, <, ^, v) and conditional instructions to control the movement of the instruction pointer across the 2D code grid.
>:1-:1
^_@The instruction pointer changes direction based on conditions or explicit commands, enabling loops, branches, and non-linear execution. This multi-dimensional flow is conceptually similar to the self-modifying code found in INTERCAL or the minimalistic movement-based logic in Brainfuck.
Befunge: I/O and String Operations
Befunge supports input and output operations using stack-based commands, including printing numbers and characters.
v
>25*"!dlroW ,olleH":v
@Strings are pushed character by character onto the stack and then output in sequence. This emphasizes the stack-centric nature of computation, conceptually similar to output manipulation in Brainfuck or INTERCAL.
Befunge: Self-Modifying Code
Befunge allows code to be modified at runtime via special commands, enabling dynamic behavior and obfuscation.
g25p
>:@The g and p instructions read and write values directly to the code grid, allowing programs to alter themselves. This is conceptually similar to self-modifying constructs in INTERCAL or reflective programming in Forth.
Befunge provides a unique, grid-based, multi-directional programming environment that challenges conventional linear execution. Its stack-based, self-modifying, and two-dimensional structure is ideal for puzzles, esoteric programming, and experimental code exploration. When studied alongside Brainfuck, INTERCAL, and Whitespace, Befunge demonstrates the creative, unconventional possibilities of programming language design.