
Code golf is a recreational activity and a type of computer programming competition where participants attempt to create the shortest possible source code to solve a particular problem. The name code golf is derived from the fact that, similar to the game of golf, participants aim for the lowest possible score or in this case, the fewest number of characters in their code. Code golfers compete for extreme brevity, and their design choices often prioritise brevity over readability. Several languages have been created specifically for code-golfing, such as GolfScript, Flogscript, Stuck, and Vyxal.
| Characteristics | Values |
|---|---|
| Type | Recreational activity/game/competition |
| Objective | Write programs that are as short as possible |
| Scoring | Lowest possible score |
| Languages | Perl, APL, GolfScript, Flogscript, Stuck, Vyxal, 05AB1E, Husk, Pyth, CJam, Jelly, etc. |
| Trade-off | Readability and legibility |
| Other names | Cramming, code-bumming |
Explore related products
What You'll Learn

Recreational activity
Code golf is a recreational activity and a type of computer programming competition. It is a challenging and fun activity for programmers. The goal of code golf is to write the shortest possible program or source code that can solve a particular problem. It is similar to the game of golf where participants aim for the lowest score instead of the highest, which is the standard in most sports. Just as golfers aim to reduce the number of club strokes, code golfers aim to reduce the number of characters or keystrokes to write a program.
The term "code golf" was first used in 1999 with Perl and later gained popularity through the use of Perl for RSA encryption. The challenging nature of optimising program size has been recognised since the early days of computing. The creation of dedicated golfing languages has further fuelled the popularity of code golf. These languages, such as GolfScript, Flogscript, Stuck, and Vyxal, are designed to allow for concise expression of ideas, sacrificing readability for brevity.
In code golf, participants prioritise brevity over other concerns such as robustness, performance, or legibility. While it may not be practical for production environments, code golf fosters creativity and leads to interesting code solutions. The focus on minimising code length can result in unconventional and innovative approaches to problem-solving.
Code golfers encounter various tasks and challenges that require strategic thinking. For example, they may need to monitor when it becomes more efficient to use a helper variable or optimise their code by replacing specific functions or strings. The competition often revolves around finding the shortest code that can produce a given output, known as the Kolmogorov complexity of the output.
Code golf websites and communities have emerged, providing a platform for programmers to showcase their skills and share their passion for code optimisation. These online spaces allow golfers to connect, exchange ideas, and compete in challenges. Some popular code golf websites include Anarchy Golf, which welcomes joke problems and free discussion, and Code Golf, which offers a range of challenges, including the Tutorial hole for beginners.
Golf GTI Turbo: Performance Boost or Marketing Hype?
You may want to see also
Explore related products

Shortest possible code
Code golf is a recreational activity or game in which participants compete to achieve the shortest possible source code that solves a given problem. The name is derived from the similarity of its goal to that of the game of golf, where participants seek the lowest score, or in this case, the fewest number of characters or keystrokes. While a traditional golfer aims to reduce their number of club strokes, a code golfer aims to reduce the number of characters required to write a program. This length of the shortest possible program is known as the Kolmogorov complexity of the output.
The term "code golf" was first used in 1999 with Perl and later gained popularity through its use in RSA encryption. However, similar informal competitions were popular earlier with APL hackers. The challenging nature of optimising for program size has long been recognised, and several new languages have emerged specifically with code golfing in mind, such as GolfScript, Flogscript, Stuck, and Vyxal. These golfing languages sacrifice readability for extreme brevity, making them esoteric.
In code golf, brevity is prioritised over other concerns such as robustness, performance, or legibility, often resulting in unique and intriguing code. For example, a Python program with many lambdas can be made more efficient by replacing each lambda with a character, such as '!'. This replacement reduces the number of characters and improves the code's golfing performance.
Code golf challenges can vary in complexity and may be named after the programming language used, such as Perl golf. Some websites, like Anarchy Golf, offer a range of coding challenges, from simple tutorials to more intricate problems. These challenges often have an "objective scoring criterion," with "shortest code" being one of the most versatile criteria. While code golf may not be suitable for practical production environments due to its focus on conciseness, it provides an exciting opportunity for programmers to showcase their skills and creativity in optimising code length.
Golf in Russia: A Growing Sport
You may want to see also
Explore related products

Readability vs. brevity
Code golf is a recreational activity or game where the objective is to write the shortest possible program that can solve a particular problem. The name is derived from the similarity of its objective with that of the game of golf, where participants seek to achieve the lowest possible score. In code golf, the length of the shortest possible program that produces a given output is known as the Kolmogorov complexity of the output.
While code golf can be an enjoyable challenge, it often comes at the cost of code readability. Readability refers to how easy it is for a person to understand the code. It is an important consideration in practical production environments, where code needs to be maintained and understood by multiple developers over time.
Golfing languages, on the other hand, prioritize extreme brevity and terseness. They are designed to allow programs to be written in a very concise manner, often sacrificing readability in the process. The syntax of golfing languages is optimized for conciseness, which can make the programs appear esoteric and challenging to understand.
Some developers prefer to write code that minimizes the number of lines and characters, even outside of code golf contexts. This practice, sometimes referred to as "playing code golf," can make the code more compact and efficient but may compromise its readability.
Readability is crucial for long-term maintainability and collaboration. When returning to a project after a break, developers may struggle to understand their own code if it is not adequately documented and readable. Clear and explicit code, with meaningful variable names and well-structured logic, facilitates understanding and reduces the time spent deciphering complex constructs.
In conclusion, while code golf can be an interesting exercise in optimizing code length, it is important to strike a balance between brevity and readability. Readability ensures that code can be maintained, debugged, and collaborated on effectively, contributing to the overall productivity of the development process. Brevity, when taken to extremes, can hinder these aspects and impact the practicality of the code in real-world scenarios.
The Founding of Izzo Golf: A Historical Overview
You may want to see also

Competition and tournaments
Code golf is a recreational computer programming competition where participants compete to create the shortest possible source code to solve a given problem. The name "code golf" comes from the similarity to the game of golf, where players aim for the lowest score, represented by the fewest strokes. Similarly, in code golf, the goal is to reduce the number of characters or keystrokes needed to write a program. This competition is a playground for programmers to showcase their skills and solve problems innovatively.
Competitions and tournaments in code golf provide an avenue for programmers to test their skills and engage in friendly rivalry. These events can vary in format, ranging from online challenges to live competitions, often incorporating time limits to add an extra layer of challenge. Some well-known programming competitions, such as Google Code Jam and Hash Code, have shut down, but new ones continue to emerge, reflecting the evolving nature of the field.
One notable aspect of code golf tournaments is the programming language used. Some competitions may require the use of a specific language, such as Perl golf, while others allow participants to choose their language. This flexibility has led to the development of dedicated golfing languages like GolfScript, Flogscript, Stuck, and Vyxal, which are designed to express ideas concisely.
The structure of code golf competitions can vary, often consisting of multiple rounds with increasing levels of difficulty. For example, the qualification round might be deliberately accessible, requiring the solution to a single problem. As the tournament progresses, participants may face more complex problems or time-limited challenges, pushing them to demonstrate their expertise and problem-solving abilities under pressure.
Code golf competitions, such as the International Collegiate Programming Contest (ICPC) and the International Olympiad in Informatics (IOI), are not just about showcasing coding skills but also endurance and algorithmic problem-solving. The IOI, in particular, has become a launchpad for young coders aspiring to make their mark in the industry, with countries investing in tech education to foster future innovation. These tournaments provide a platform for programmers to connect, exchange ideas, and push the boundaries of what can be achieved with code.
Swingrite Golf: Perfect Your Swing
You may want to see also

Golfing languages
Code golf is a recreational computer programming competition where participants aim to write the shortest possible source code to solve a given problem. The name "code golf" is derived from the similarity of its objective to that of the game of golf, where players try to complete the course in the fewest strokes. Similarly, in code golf, participants strive to reduce the number of characters or keystrokes needed to write a program. This competition has given rise to dedicated golfing languages, specifically designed to enable concise expression of ideas in code.
Several new languages have been created with code golfing in mind, including GolfScript, Flogscript, Stuck, and Vyxal. These languages are Turing-complete and provide constructs that facilitate concise code. For instance, GolfScript allows printing 1000 digits of pi with a relatively compact code structure.
In addition to these dedicated golfing languages, code golf challenges may be posed in more mainstream programming languages such as Perl, which was associated with the earliest use of the term "code golf" in 1999. Other popular languages in the code golf community include 05AB1E, Husk, Pyth, CJam, and Jelly. The focus on brevity in code golf can influence coding practices beyond golfing languages, as some developers strive for concise code even in languages like Python, where readability is typically prioritised.
Code golf websites and communities have emerged, fostering the creation of novel golfing languages and dialects. For example, the "open" nature of some code golf questions, which do not mandate a specific programming language, has led to the development of specialised dialects like REBMU, based on the REBOL language. These dialects aim to provide additional flexibility in solving code golf problems.
Golf's Evolution: Trends and Transformations
You may want to see also
Frequently asked questions
Golfing coding, or code golf, is a recreational activity or game where the goal is to write a program that solves a problem in the fewest number of characters.
The term "code golf" is derived from the similarity of its goal with that of the game of golf, where participants seek to achieve the lowest possible score. Similarly, in code golf, participants aim to reduce the number of characters or keystrokes needed to write a program. The term was first used in 1999 with Perl.
Golfing languages are designed to allow programs to be written concisely, often sacrificing readability for brevity. Examples of golfing languages include GolfScript, Flogscript, Stuck, and Vyxal.
Anarchy Golf, also known as "anagol", is one of the longest-running code golf websites. It features joke problems and allows for open discussion and spoilers. Other code golf websites include those that support esoteric languages, such as 05AB1E, Husk, Pyth, CJam, and Jelly.


















