Code golf
Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem. Code golf challenges and tournaments may also be named with the programming language used.
Etymology
The term "code golf" is derived from the similarity of its goal with that of conventional golf, where participants seek to achieve the lowest possible score, rather than the highest, as is the standard in most sports and game scoring systems. While conventional golf players try to minimize the number of club strokes needed to complete the course, code golfers strive to reduce the number of characters necessary to write the program.History
The length of the shortest possible program that produces a given output is known as the Kolmogorov complexity of the output, and its mathematical study dates to the work of Andrey Kolmogorov in 1963. Code golf, however, can be more general than this, as it often specifies a general input-output transformation that must be performed rather than asking for a single output with no input.Whilst the term "code golf" was apparently first used in 1999 with Perl, and later popularised through the use of Perl to write a program that performed RSA encryption, a similar informal competition is known to have been popular with earlier APL hackers. The challenging nature of aggressively optimizing for program size has itself long been recognized; for example, a 1962 coding manual for Regnecentralen's GIER computer notes that "it is a time-consuming sport to code with the least possible number of instructions" and recommends against it for practical programming. Today the term has grown to cover a wide variety of languages, which has even triggered the creation of dedicated golfing languages.
Dedicated golfing languages
Several new programming languages have been created specifically for the practice of code golf. These languages sacrifice readability for extreme brevity, and often provide high-level functions with single-character names, which makes them unsuitable in production environments where maintainability has higher importance than code size.History
The first recorded dedicated golfing language is GolfScript, released in 2007, with a derivative called floGScript releasing the next year.In 2014, CJam, heavily inspired by GolfScript, released.
in 2015, motivated by CJam and APL, and inspired by J, Jelly released, and would position itself as a dominant contender for tersest language for many years.
Since 2015, many dedicated golfing languages have been released. Notable examples include Japt, Pyth, 05AB1E, Charcoal and Vyxal.
Design
Some golfing languages, such as Japt and Pyth, are transpiled to conventional programming languages. This makes the languages easier to learn, and guarantees a solid foundation for the design and performance of the language. This also simplifies the creation of web interpreters, which allow users to use the language without downloading anything.Many modern golfing languages, being inspired by or related to golfscript, are stack-based and concatenative, but several languages inspired by Jelly, itself tacit and functional, instead follow its footsteps. Other paradigms, such as pattern matching languages, also appear in less notable quantities.
Most golfing languages are high-level, and almost all shorten symbols to a single character. In modern implementations, such as in Vyxal, the languages leverage single-byte character sets to make all commands printable, which further reduces readability due to the variety of symbols, especially with the incompatibility of code comments with the goal of code golf.
Golfing languages almost always make heavy use of operator overloading, and most include easily-accessible forms of text compression. In most languages, closing parenthesizes and other syntactic structures is optional at the end of the program. As a general design principle, dedicated golfing languages are heavily implicit, and most are tacit.
Examples
An example of GolfScript code to print 1000 digits of pi:An example of Vyxal 3 code for Fizz buzz, annotated with an explanation: