upvote
For things that learn (humans, AI's-while-training), it's a useful exercise.

And things that play (humans), it's a useful diversion.

The sport gives you an incentive to learn a language, library, or algorithm more deeply and to discover new ways to think about how they work. It's very useful.

reply
I suspect it may be useful for AIs too.

In current models, context is limited and attention is expensive, the shorter the code the more you can have in a given context window. Code golfing techniques could help a LLM see further within a given context window.

reply
It's a purely recreational activity. But there's a surprising amount of depth to it--the skill ceiling is extremely high and it's not uncommon for thought-to-be optimal solutions to be beaten years later. There's lots of crazy math and algorithm tricks you will never see in conventional programming. Getting good at code golf requires mastering not only the language, but lots of math and algorithmic skills as well.

Part of the fun is also doing things you're not supposed to do. Not only does it become unreadable, but you often are abusing dark corners of the language and implementation.

reply
Speed golfing also often makes code unreadable and unmaintainable to some degrees. Everything is a trade-off.
reply
Very first (and last) coding competition I entered was in ~1991. It was on a local BBS and the challenge was to find all primes from 0-1000. Four scoring metrics were correctness, code size, size of executable and speed of solving.

I took that opportunity to learn a bit of assembly. I’m guessing it was 100 lines of code, COM size was ~100 bytes and it could do the whole test in less than 100ms. I got second place to a turbo pascal entry that had a much larger binary, took 5-10 seconds but it was maybe ten lines of very readable code.

Made me realize that folks really value readability (and to ask how metrics are weighted )

reply
Kind of funny how Zach Barth, while designing engineering games, noticed this distinction between speed, size and time and just made each of the three separate leaderboards in all of his games. But actual serious engineers making "more" serious playthings seemingly couldn't figure it out.

e: Autocorrect did the worst thing you could do to Barth's name.

reply
But it's justified. Efficiency on key parts of the code, of course. Not on the entire code base.

You can mitigate the unreadability in many ways. For example c++ allows to generate magic numbers using constexpress, where the code itself is clear and human readable.

You can create a loop to calculate a lookup table and store it into a small number of uint64. The code shows what the magic numbers mean, and can be debugged.

reply
The reduction of code size in general is called an abstraction. So it is also justified as long as it is not taken to the extreme.
reply
Top code golf just uses languages where the characters are compressed, and the notation is abused. So the winners read like hfE#^gg
reply
"Winners" depends on the where you're competing. Many places include langauge-specific leaderboards, so your Python is not competeing against my GolfScript.

Incidentally, in my experience, the strongest human competition usually is in Python.

reply
Now your hourly builds have to redo the expensive calculation in perpetuity.
reply
The alternative is doing it even more often on production servers or your users old laptop.

Always do as much as possible at compile time, unless it bloats your binary size or makes things slower with cache misses.

reply
It's about as useless as regular golf. The point is not to be useful, but as a fun competition and a demonstration of a niche skill.
reply
But they should had focused the ai into beating speed golf instead of code golf.
reply
Code golf is pure fun. Or, was, I guess
reply
Hiking didn't stop being fun the day cars were sold.
reply
What is speed golf?
reply
Speed golf is the fastest code. Stack Exchange has a site where speed golf is fused with code golf.
reply
deleted
reply