Code Golf

What is code golf and what are the benefits for developers and companies?

[et_pb_jt_typewriter type_speed=”40″ back_delay=”0″ start_delay=”10″ smart_backspace=”off” show_cursor=”off” _builder_version=”4.0.10″ text_font_size_tablet=”51″ text_line_height_tablet=”2″ prefix_text_font_size_tablet=”51″ prefix_text_line_height_tablet=”2″ typed_text_font_size_tablet=”51″ typed_text_line_height_tablet=”2″ typed_cursor_font_size_tablet=”51″ typed_cursor_line_height_tablet=”2″ suffix_text_font_size_tablet=”51″ suffix_text_line_height_tablet=”2″][et_pb_jt_typewriter_text text=”Knowledge at a glance: Code Golf is a competition between programmers in which the one wins who solves a programming task with the fewest characters.” _builder_version=”4.0.10″ typed_text_text_color=”#ffffff”][/et_pb_jt_typewriter_text][/et_pb_jt_typewriter]

The solution with the fewest characters wins

Code Golf is a competition between programmers. Like golf, where athletes try to put a ball into a hole with as few strokes as possible, the one who solves a task with as few characters as possible wins. Mostly implementations in a predefined programming language are compared. Setting time limits for the submission of solutions is also not uncommon.

The origin of code golf goes back to a Perl community, where developers started to solve a basic task in a thread with decreasing amounts of code. In July 2000, the First Annual Perl Golf Apocalypse was proclaimed.¹ Today, code golf is also called script golf, as scripting languages such as Ruby, Rust, Phython, PHP, JavaScript, Lisp, etc. are often used in competitions. Alternatively, it is sometimes called Spartan programming.

What is the benefit of Code Golf?

What is the benefit of code golf for software developers?

  • Participating in a contest is fun for many developers.
  • It allows the comparison of solutions of different developers. Such a comparison is usually rarely possible in software development, because usually teams work together on a solution or individual developers take care of individual tasks or requirements.
  • It helps to improve skills, e.g. when features of programming languages are used that are rarely or never used.
  • It could also be a training for whiteboard coding.

And where is the benefit for companies? Of course companies are interested in good software developers and high-performance solutions, but most of all they are interested in solutions that are easy to understand and maintain. Developers not only spend a lot of time reading code implemented by other developers during a code review, but often – e.g. during a refactoring – they also deal with lines of code that they themselves wrote earlier. For a competition, it may make sense to shorten variable or function names to single letters – as some minifiers do – or to do without comments, but in a professional context, colleagues and clients will rarely be happy about this. Certainly it makes sense to minimise the number of variables, to avoid persistent variables or to use short, meaningful variable names – but always with a view to the traceability and maintainability of a software.

Code Golf


[1] Annoucing the First Annual Perl Golf Apocalypse

If no specific programming language is specified in a competition, the development of own programming languages is also possible. A list of so-called esoteric programming languages or Golfing Languages can be found here.

In a certain way there is a similarity between Code Golf and Code Kata. A code kata is an exercise that focuses on learning new skills and developing successful routines. One difference is that a code kata is about finding multiple solutions, whereas code golf is about implementing one with the fewest characters.

If you are interested in code golf examples, you will find a nice collection here.

We like to support you!

Software Development from Berlin


Here you will find additional information from our Smartpedia section:

Smartpedia: How does a Code Review work?

How does a Code Review work?

Smartpedia: What is Refactoring?

What is Refactoring?