Here's the strange sport Googlers play to refine their programming skills
Google em
ployees have a novel way of relaxing while also helping to refine their programming skills: "Code golf."Code golf is guided by the same basic principle as real golf: Achieve your objective as efficiently as possible. In regular golf, this means getting the ball in the hole in as few strokes as possible. In code golf, it means solving a specific problem using as little code as possible.
In a blog post earlier this month, former Google employee Zhen Wang details how the unusual sport took hold at Google.
While on leave in mid-2014, the software engineer was thinking about dwelling on the "convoluted Java frameworks widely adopted at work." They "sucked the fun [out] of programming like a Pastafarian monster slurping all the tomato sauce on a plate of spaghetti." So, he decided to do something about it:
To bring back the fun while fostering a culture that hails code brevity, I decided to start a 20% project to create an internal code golf platform - a playground for Google engineers to show off wits, a fountain of programming tricks for the studious, and a symbol of defiance against the trend of technical complexity permeating through the company. Later in the development, it occurred to me that the system could also be purposed as a recruiting tool: interviewers would benefit from a growing repertoire of coding questions with high-coverage test cases against which candidates's code can be automatically validated. And that became the ostensible mission statement on the code golf site to justify the business case ;)
Of course, Zhen Wang didn't invent code golf. There are plenty of public code golf competitions, including on JAGC.org, and Stack Exchange. (There's also an inactive Reddit community dedicated to the sport.) And similar challenges have been taken on by programmers looking to test their skills for years - notably the "demoscene." It's a community dedicated to creating extravagant audio-visual presentations using as little storage space as possible, and has been around for decades.
However, the former Google employee says that "the top voted entries on Stack Exchange are just not on par with the best solutions I've witnessed at Google, which exude an elevated level of creativity and craftsmanship rarely found elsewhere. Reading the code can easily trigger a software engineer's imposter syndrome, a profound feeling of humbleness, tinged with a sense of proudness to be working with these talented people."
Hundreds of Google employees have taken part, he says, with some of them even "[confessing] in private that they had developed an unhealthy addiction that negatively impacted their productivity."
So what sort of challenges come up in code golf? Here are a few examples:
- Translate Roman numerals into Arabic numbers (i.e. standard base 10). CCLXXXIII translates to 283, for example, while MCMLXXXVIII is 1988. The shortest answer, written in programming language perl, provides a solution using just 82 symbols.
- Reading a clock face. A "clock face," created using ASCII symbols is inputted; the solution needs to translate it into the time shown. One solution on Stack Exchange, written in Python, uses 205 characters.
- Calculate the resistance of a resistor network. Like reading the clock face, the resistors are drawn using ASCII symbols. A solution on JAGC manages it in 279 symbols.