The question of the role of code-golf on CodeReview was raised back in April. There was very little discussion, but there seemed to be a strong consensus at the time among meta users that code golf was not on topic (7 upvotes, 0 down votes).

Recently though a code-golf question was posted. Upon reading it, I voted immediately for closure, but then I realized that it's received quite a positive response (4 upvotes on the question, and 6 answers, all within 24 hours). This has made me wonder if maybe my feelings towards code golf are not shared by a majority of users.

To me, the goal of Code Review is to achieve the highest quality of code possible, meaning maintainability, readability, etc--the typical benchmarks of code quality, not a metric of shortness. With that in mind, I feel that code golf questions are just about the antithesis of CR. I'm curious on others' thoughts though. Maybe there's some value to it that I'm not seeing?


4 Answers 4


Well, let's dig deeper and ask, what is the point of code golfing? It's mental exercise, similar to the usual code reviews, but with a slightly twisted goal. I think that golfing can be beneficial for helping to truly understand a language, including all its syntactical details and standard library features.

What is the thought process involved in golfing? I think it goes more or less like this:

  1. Switch to a simpler algorithm, if possible
  2. Stop doing obviously stupid stuff, such as repeating code
  3. Stop doing luxurious stuff like error handling
  4. Stop doing sensible stuff such as initializing variables in C
  5. Look for micro-optimizations that save a character or two
  6. Minify identifiers, reduce parentheses and braces, strip whitespace and eliminate comments

On this site, we routinely do (1) and (2). Of course, code quality diminishes as you proceed past step (2). When you read golfed code, you mentally undo (6) → (5) → (4) → (3) → (2). Shortening beyond (2) feels like it should be off-topic for this site.

Golfing on the Code Golf SE is quite a different ball game!

  • Code Golf SE allows responses in any language, including GolfScript.
  • Code Golf SE usually poses a question, and asks responders for blank-slate solutions. Golfing on this site, if allowed, would still be a review of some sort. Many of the responses have all explained how to shorten the code relative to the original, in a way that you could learn from each suggestion.

What accounts for the popularity of the questions https://codereview.stackexchange.com/q/33827/9357 and Python server that only returns error 418? One factor is that they were posed in Java and Python, respectively — two "straitjacket" languages that are designed to thwart obfuscation. In C or Perl, the outcome might have been uglier, both in terms of the code and the audience response. Another consideration is that they were both extremely simple tasks with not too many different possible approaches.

Given that…

  • Code golfing is not an entirely pointless sport
  • There may be people who prefer Code Review-style golfing as opposed to Code Golf and Programming Puzzles-style golfing

… do we still want to allow golfing here?

Possible answers, I think, are:

  1. Yes, we can practice a gentler style of golfing here than on Code Golf SE. Just tag questions so that users who are disgusted by the idea can ignore them.
  2. No, allowing golfing risks splitting the community, devaluing the reputation scores of the "good" programmers, and contradicting our site's elevator pitch. The distinction between Code Golf and this site would be too fine for users to understand. (They already have enough difficulty knowing which questions belong on Stack Overflow or Programmers instead.)

Considering all of the above, I'd vote no. In my opinion, although those two questions were kind of fun, they shouldn't set a precedent. I'd be in favour of having them and the tag deleted from this site to prevent the proliferation of future golfing questions.

  • 4
    \$\begingroup\$ BURNINATION! Haha. Anyway, +1 from me. I like this approach and the details. We can certainly advocate shorter but still good code, without digging into the "evils" of code-golfing. I'm okay with killing this tag, but we can probably just close those two questions while using a custom close reason. I do fear that if visitors see this tag, they may hastily post a "contest" entry on the original code, which could then encourage code blocks as answers (which we discourage). \$\endgroup\$
    – Jamal
    Commented Nov 6, 2013 at 21:45
  • \$\begingroup\$ I like the second possible answer. \$\endgroup\$ Commented Nov 11, 2013 at 17:55

I agree there is already a site called CodeGolf, let them review their own Golfing skills.


Oh boy, this is going to be some discussion...

@Winston Ewert did give a good point: let the community decide. The mods shouldn't create their own rules as it's the community's role is supposed to drive the site. However, the community can easily be divided on a situation, as is sort of going on in this question. It has received upvotes, good answers, and @svick had already created a tag. But, fortunately, the answers do not represent those found on Code Golf SE. That's a good sign.

In terms of reviewing, here's how I see it. If the OP merely requests "the shortest code possible" instead of specifically code-golfing, that may work. The answers could then help the OP give good but short code. Maybe even the shortest possible, as long as it doesn't specifically involve squeezing out every last bit of whitespace. I'm okay with that. Short code isn't always bad, but it may also help to tell the OP that "code-golfing" goes against good coding practices.

The votes, on the other hand, can create bias. We cannot assume that every single user will be interested in only upvoting on-topic questions. If the question looks intriguing, it alone could warrant an upvote. But, as I've seen, we cannot give special treatment to each popular question. If it's clearly off-topic, then it should be closed. If this still divides the community, then a consensus will need to be reached. It doesn't have to satisfy everyone. If it were, then this would still be going.

tl;dr: I'm okay with assisting with shortening code as long as it doesn't fall into code-golfing.

  • \$\begingroup\$ Hmm it's an interesting point that brevity could actually be a positive measure of code quality. I just don't know if that would ever actually be the case though. Either way +1. I hadn't considered that code golf type questions might actually have some tangential review value. (Interestingly, the question you linked--which is the one I had in mind when writing this question--has been closed and then migrated since yesterday. Guess it seems I may have jumped the gun on even asking this quesiton :).) \$\endgroup\$
    – Corbin
    Commented Nov 7, 2013 at 5:44
  • \$\begingroup\$ @Corbin: To be honest, I was writing this answer late at night. :-) I'm glad I still made some sense here. I do thin you were right in asking this question. I should've felt hesitant about accepting the new [code-golf] tag. Unfortunately, the migrated question still has this tag, and that question cannot be edited on here anymore. No harm done. At least it appears that we're in favor of keeping code-golfing off-topic. \$\endgroup\$
    – Jamal
    Commented Nov 7, 2013 at 5:51
  • \$\begingroup\$ Now that the FizzBuzz question has been migrated to Code Golf SE, we all look like such golfing amateurs. =) \$\endgroup\$ Commented Nov 7, 2013 at 6:10
  • \$\begingroup\$ @200_success: I've tried to golf once in C++, but it didn't work out so well. Though, I suppose my decision to use C++ of all languages for golfing really speaks amateur... \$\endgroup\$
    – Jamal
    Commented Nov 7, 2013 at 6:16

I think the most notable type of codegolf question which should be off-topic here is the character count type question (I have solved problem Foo with X characters, how can I make it shorter?). Those should be closed and possibly migrated (although as I understand this is not quite as easy at least while we are in beta) to Code Golf as the OP is probably not really interested in a well written solution anyway.

It gets trickier if someone posts a piece of code which solves a particular problem and asks how to make it shorter. Question would be what the threshold is where it becomes a pure codegolf question. Usually less code is better but at some point it becomes just bad code, hard to read and maintain and code review should be about good code (clean, easy to read an maintain). I guess that would have to be decided by the community through close votes on a case by case basis.

  • \$\begingroup\$ My understanding is that they don't take individual requests for code-golfing. The OP would have to make it into an actual contest, as described in that FAQ. \$\endgroup\$
    – Jamal
    Commented Nov 6, 2013 at 21:53
  • 2
    \$\begingroup\$ Ah ok, well that would mean that these kind of code-golf reviews are nowhere really on-topic, wouldn't it? \$\endgroup\$
    – ChrisWue
    Commented Nov 6, 2013 at 22:44
  • 1
    \$\begingroup\$ Isn't golf an individual sport anyway? \$\endgroup\$ Commented Nov 6, 2013 at 23:47
  • \$\begingroup\$ @retailcoder: Yes, but it's a little different on CG SE. :-) Everyone is still trying to score a hole-in-one, though. \$\endgroup\$
    – Jamal
    Commented Nov 7, 2013 at 0:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .