Editing 1960: Code Golf

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 8: Line 8:
  
 
==Explanation==
 
==Explanation==
This was the first comic in the ''[[:Category:My Hobby|My Hobby]]'' series in over a year. It directly followed the second ''[[:Category:Fun fact|Fun fact]]'' comic in the same month, [[1959: The Simpsons]], after more than two years break from that series. It seems that [[Randall]] returned to his [[#Revitalizing_old_themes|old themes]] this month.
+
This was the first comic in the ''[[:Category:My Hobby|My Hobby]]'' series for over a year. It followed directly after the second ''[[:Category:Fun fact|Fun fact]]'' comic in the same month, [[1959: The Simpsons]], after more than two years break from that series. It seems that [[Randall]] returned to his [[#Revitalizing_old_themes|old themes]] this month.
  
{{w|Code golf}} is the attempt to use as few characters as possible to write a computer program with a certain function, analogously to {{w|golf|regular golf's}} goal of getting the ball into the hole with as few strokes as possible. Reverse code golf would be to write a given program, probably to achieve a trivial outcome, using as many characters as possible. Randall's approach to this in the code example shown in the comic is to create overly long function names, using [https://en.wikisource.org/wiki/Moby-Dick_(1851)_US_edition/Chapter_1 the beginning lines] of {{w|Herman Melville}}'s notoriously long-winded whaling novel ''{{w|Moby-Dick}}''. Regular code golf also results in names of functions and variables that have nothing to do with their purpose in the program, but would minimise their length.
+
{{w|Code golf}} is the attempt to use as few characters as possible to write a computer program with a certain function, analogously to {{w|golf|regular golf's}} goal of getting the ball into the hole with as few strokes as possible. Reverse code golf would be to write a given program, probably to achieve a trivial outcome, using as many characters as possible. Randall's approach to this in the code example shown in the comic is to create overly long function names, using [https://en.wikisource.org/wiki/Moby-Dick/Chapter_1 the beginning lines] of {{w|Herman Melville}}'s notoriously long-winded whaling novel ''{{w|Moby-Dick}}''. Regular code golf also results in names of functions and variables that have nothing to do with their purpose in the program, but would minimise their length.
  
 
Using "as many characters as possible" to produce code is known as "Code Bowling" in the code golf space. Code bowling challenges usually come the requirement of being "pristine" meaning every substring of the code is necessary, and also often have restrictions on whitespace and identifier length. Without these restrictions it would be a trivial task to make any given program longer by inserting useless code or comments. Furthermore, some programming languages place no limit on function names, so these could simply be made longer. The program listed here would not meet the requirements of most challenges. The code is written in a programming language that looks similar to {{w|Python (programming language)|Python}}, but with the keyword “define” instead of “def” to define functions. Python has no limit for function name length, and was previously featured in comic [[353: Python]].
 
Using "as many characters as possible" to produce code is known as "Code Bowling" in the code golf space. Code bowling challenges usually come the requirement of being "pristine" meaning every substring of the code is necessary, and also often have restrictions on whitespace and identifier length. Without these restrictions it would be a trivial task to make any given program longer by inserting useless code or comments. Furthermore, some programming languages place no limit on function names, so these could simply be made longer. The program listed here would not meet the requirements of most challenges. The code is written in a programming language that looks similar to {{w|Python (programming language)|Python}}, but with the keyword “define” instead of “def” to define functions. Python has no limit for function name length, and was previously featured in comic [[353: Python]].
Line 16: Line 16:
 
The first two functions defined implement “zero” and “successor”, the two basic operations of {{w|Peano axioms|Peano arithmetic}}. Presumably, the programmer will next implement natural number addition, then integers, then whichever branches of mathematics the original problem needs, all from scratch. Generally, you would use built-in functions to perform mathematical operations, so it is redundant to implement them yourself from scratch.
 
The first two functions defined implement “zero” and “successor”, the two basic operations of {{w|Peano axioms|Peano arithmetic}}. Presumably, the programmer will next implement natural number addition, then integers, then whichever branches of mathematics the original problem needs, all from scratch. Generally, you would use built-in functions to perform mathematical operations, so it is redundant to implement them yourself from scratch.
  
The title text suggests that Randall has also invented a reverse version of regular golf, where the aim is to take as many strokes as possible to get the ball in the hole. Similarly to ''Reverse Code Golf'', the only challenge here would be the player's own boredom threshold, since they could always add more strokes by tapping the ball in a direction other than that of the hole.
+
The title text suggests that Randall has also invented a reverse version of regular golf, where the aim is to take as many strokes as possible to get the ball in the hole. Similarly to ''Reverse Code Golf'', the only challenge here would be the player's own boredom threshold, since they could always add more strokes by tapping the ball in a direction other than that of the hole.
Alternatively, he actually plays golf in reverse, starting from the hole (or pin) and hitting the ball towards the tee (he may or may not also be playing in the opposite direction of the hole layout established by the organisation which manages the course). This would however, be a flagrant violation of the Laws and Customs of Golf, as it interferes with other players' games and some aspects are impossible or unpractical (if Randall takes the view that the ball should start in the hole, the rules prohibit using any clubs to remove it in that it would damage the hole, and he would have to putt off the green).
 
  
The comment that he has "been playing for years all across the country and <nowiki>[</nowiki>is] still on the first hole" is ambiguous. Normally, when a golfer says they have been playing all across the country they mean that they have played rounds at many different courses. Randall could be implying the same, but that he's never finished the first hole (which, as noted above, would hardly be surprising), and so still counts it as playing one continuous first hole. Alternatively, he may literally mean that he has been playing the ball continuously across the whole country. Under normal golf rules this would result in his shots going "[https://en.wikipedia.org/wiki/Out_of_bounds#Golf Out of Bounds]" when it went beyond the boundaries of the original course. In one way, this would help him, as he would incur a penalty stroke. However, he would then have to play his next shot from the same spot as the last one, which would hamper him from continuing to play across the country. Since Randall has invented the sport, though, he may have chosen not to include Out of Bounds rules.
+
The comment that he has "been playing for years all across the country and <nowiki>[</nowiki>is] still on the first hole is ambiguous. Normally, when a golfer says they have been playing all across the country they mean that they have played rounds at many different courses. Randall could be implying the same, but that he's never finished the first hole (which, as noted above, would hardly be surprising), and so still counts it as playing one continuous first hole. Alternatively, he may literally mean that he has been playing the ball continuously across the whole country. Under normal golf rules this would result in his shots going "[https://en.wikipedia.org/wiki/Out_of_bounds#Golf Out of Bounds]" when it went beyond the boundaries of the original course. In one way, this would help him, as he would incur a penalty stroke. However, he would then have to play his next shot from the same spot as the last one, which would hamper him from continuing to play across the country. Since Randall has invented the sport, though, he may have chosen not to include Out of Bounds rules.
  
Interestingly, the comic ends with an unmatched left parenthesis (something which might be intended to [[859|create unresolved tension]]<!-- ) -->.
+
Interestingly, the comic ends with an unmatched left parenthesis, (something which might be intended to [[859|create unresolved tension]]<!-- ) -->.
  
 
==Transcript==
 
==Transcript==
Line 32: Line 31:
  
 
:[Caption under the black box:]
 
:[Caption under the black box:]
:My hobby:
+
:My hobby: Reverse Code Golf
:Reverse Code Golf
+
 
  
 
==Trivia==
 
==Trivia==

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)