What is code golf and what are the benefits for developers and companies?
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.
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.
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.
Here you will find additional information from our Smartpedia section: