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 12: Line 12:
 
{{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_(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.
  
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 actually an impossible goal. 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. Even if the language Randall is using does limit function name length, he has not maximised the ones he has used, since the first two are 50 characters long, and the last much shorter. 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]].
  
 
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.

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)