# Code golf variant: by token [duplicate]

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?

• 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. – Chris Jester-Young Mar 28 '14 at 13:43
• Ungolfed means the same program as the golfed but with proper identifier names and with proper indentation. – Chris Jester-Young Mar 28 '14 at 13:51
• 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" – skibrianski Mar 28 '14 at 13:55 • 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. – Chris Jester-Young Mar 28 '14 at 13:59
• 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? – skibrianski Mar 28 '14 at 14:05
• That is how I interpret it, yes. – Chris Jester-Young Mar 28 '14 at 14:07
• @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. – dmckee --- ex-moderator kitten Mar 28 '14 at 14:44
• Looks like someone blew away the link to meta.codegolf.stackexchange.com/questions/403/… – skibrianski Mar 28 '14 at 18:53