1
\$\begingroup\$

I've come to the conclusion that code golf can be either good (eg reducing unnecessary operations like assignments) or bad (eg reducing character count of variable names).

It strikes me that better a better metric than character or byte count would be to count the number of tokens in a program, eg:

$number_of_matches = $? ? 3 : 4;
        ^          ^  ^ ^ ^ ^ ^^

would count the same as:

$n=$??3:4;
^ ^^ ^^^^^

As both have 8 tokens.

This would let us preserve readability but still leave the non-repetitive part of code-golf. This would also have the advantage of leveling the playing field somewhat with languages that tend to prefer longer function names.

Thoughts?

\$\endgroup\$
8
  • 1
    \$\begingroup\$ The whole point of golfed programs is to be illegible! I feel this proposal would take away half the fun. Besides, we already encourage people to post an ungolfed version as an accompaniment. \$\endgroup\$ Commented Mar 28, 2014 at 13:43
  • \$\begingroup\$ Ungolfed means the same program as the golfed but with proper identifier names and with proper indentation. \$\endgroup\$ Commented Mar 28, 2014 at 13:51
  • 1
    \$\begingroup\$ Right, but un-golfed is different from "with minimal tokens". eg: "$radius = sqrt( $x * $x + $y * $y ); return PI * $radius * $radius" vs. "return PI * ( $x * $x + $y * $y )". the latter has fewer tokens, the former is more "un-golfed/readable" \$\endgroup\$ Commented Mar 28, 2014 at 13:55
  • \$\begingroup\$ If your golfed entry says return P*($x*$x+$y*$y), then ungolfed means you might say return PI * ($foo * $foo + $bar * $bar), but you cannot transform it to the $radius version; that would be different to (not "the same as") the golfed version. \$\endgroup\$ Commented Mar 28, 2014 at 13:59
  • \$\begingroup\$ Interesting, so you would say that "un-golfed" just means code gets indented and variable names get expanded, no other readability optimizations whatever are done? \$\endgroup\$ Commented Mar 28, 2014 at 14:05
  • \$\begingroup\$ That is how I interpret it, yes. \$\endgroup\$ Commented Mar 28, 2014 at 14:07
  • \$\begingroup\$ @skibrianski I think that what you write is the minimal version of "un-golfed". Because I often write reasonable code for proof of concept and then work several transformation on it by way of golfing I sometimes post a slightly nicer version then the minimal one. \$\endgroup\$ Commented Mar 28, 2014 at 14:44
  • \$\begingroup\$ Looks like someone blew away the link to meta.codegolf.stackexchange.com/questions/403/… \$\endgroup\$ Commented Mar 28, 2014 at 18:53

0

Browse other questions tagged .