Code Golf

Code golf is the practice of writing a program that solves a given problem using the fewest possible characters, or more often the fewest bytes, of source code. The name borrows from the sport of golf, where the goal is the lowest score: in code golf the winner is whoever reaches a working solution in the smallest amount of code, regardless of how readable or efficient it is at runtime.

The activity has a dedicated home in the Programming Puzzles and Code Golf community on Stack Exchange, where members post challenges and compete to post the shortest answer in any language. Each question defines the task and the scoring rule, answers are measured in bytes, and the community has built up elaborate conventions for what counts as a valid program, how input and output may be handled, and which loopholes are forbidden. This turns a casual pastime into something closer to a measured competitive sport with shared, enforced rules.

Code golf has driven the creation of an entire family of so-called golfing languages, which the esoteric-language community catalogs alongside other unusual designs. Languages such as GolfScript, Pyth, Jelly, and 05AB1E are built specifically to make short answers shorter, packing common operations into single bytes so that a task taking dozens of lines in C might collapse into a handful of cryptic characters. These languages overlap heavily with esoteric programming languages, since both prize terseness and cleverness over everyday practicality.

The result of golfing is code that is extremely compact and almost always unreadable, which puts code golf close in spirit to obfuscated code contests like the IOCCC. The difference is one of objective: obfuscation aims to confuse, while golfing aims for brevity, and the confusion is a side effect. Both pursuits reward a deep, almost intimate knowledge of a language’s smallest features, and both are firmly part of hacker culture’s tradition of treating programming constraints as a game.