For programmers

Fore! How code golf became a thing at Google

A regular internal coding competition allows Google developers to show their creativity and also helps with hiring other engineers

Zach Johnson hitting a tee shot at the British Open
REUTERS/Russell Cheyne

For programmers

Show More

This past weekend in Scotland, the best golfers in the world gathered to compete in the British Open, one of professional golf’s top events of the year. Golf, of course, is one of the most popular recreational sports here in the United States. It turns out that even software developers and, in particular, engineers at Google, really like golf, although their preferred form of the game involves programming code and algorithms, instead of balls and clubs.

Code golf, if you’re not familiar with it, is something that was first developed among the Perl community in the late 1990s. It’s basically a coding competition, where developers compete to solve a programming challenge with as little code as possible. Low score, in terms of total bytes, wins, hence the association with golf. A number of sites are devoted to code golf, some language specific, others not.

Recently, code golf has really taken off among Googlers, thanks to the work of one their former engineers. During a two week leave from Google last year, Zhen Wang, feeling that large coding frameworks in use at the company had taken some of the fun out of programming, decided to launch a 20% project to build an internal code golf platform. The idea, as Wang wrote on his blog, was to make coding fun again by building  “... 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.”

As Wang told me via email, he built the code golf platform during that two week leave, and launched it in June, 2014. The platform, which is accessible only to Google employees, allows for solutions to be written in a handful of languages (JavaScript, Go, Python, C++, and Haskell). Submitted solutions that pass all of the associated automated tests are then scored on total byte size. The low score in each language wins.

A hit with engineers

The platform quickly proved to be a hit with Google engineers. Wang wrote that the weekly challenges soon attracted submissions from hundreds of Googlers and he told me that, on average, there were about 20 correct solutions submitted per language. Why has code golf proven to be popular at Google? “I think code golf channels the competitive spirit of talented engineers through a fun game where they can express their creativity and learn from each other,” Wang told me. “DEC in the 80's had a similar battle of language. Google with its strong technical workforce is the DEC of this era. It's no coincidence that code golf becomes a hit there.”

Googlers show their creativity

Mostly, though, what impressed Wang the most was the quality of the winning entries. “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,” he wrote on his blog.

I asked Wang if there were any particularly clever solutions that stuck out in his mind and he shared this with me:

“As of today, if you search for ‘python roman numerals’ on Google, you'll find a large body of integer-to-roman-numeral conversion routines written in Python, none of which is as short or as clever as a 84-byte one-liner painstakingly crafted by a long-time Python golfer at Google. To everyone's biggest surprise, his solution was eventually dethroned by a straightforward 74-byte entry which utilized a super obscure, built-in library function in formatter.AbstractFormatter.”

A useful hiring tool

While code golf is mainly done for  fun, Wang also helped to justify his project by suggesting that it would be useful in hiring developers. Specifically, he felt that the challenges would form a library of good interview questions for engineering candidates, while the test cases could be used to automatically validate a candidate’s code.

Of course, during the interview process, it’s a correct solution that matters, not the length of the code. The size of a candidate’s solution “would be as meaningless a metric as their penmanship on whiteboard,” Wang told me. “It'll be ludicrous to penalize candidates who aren't proficient at byte shaving because real world programming rarely demands or benefits from code golf techniques,” he said.

However, Wang still believes that success at code golf can be an indication of programming skill. “I believe code golf masters are highly skilled developers that IT companies should chase after,” he wrote to me. “Excelling at code golf is a strong signal of programming language expertise and creative thinking abilities.”

While Wang has since left Google and now works as an independent app developer (he’s just created an app call Circadi), code golf remains popular at Google. He says that his contacts there report that it continues to attract new contestants and high quality solutions. Just don’t expect to see anybody from Google hoisting the Claret Jug anytime soon.

ITWorld DealPost: The best in tech deals and discounts.
Shop Tech Products at Amazon