Editing 1275: int(pi)

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 comic purports to provide a tip to programmers, that the number "{{w|3 (number)|3}}" is cursed and shouldn't be used. There is no explanation given as to why the number 3 is cursed, and it could well have been chosen arbitrarily. The title text hints that the consequence for using the cursed number is non-functioning code, a pain for any programmer. The absurdity of the number 3 somehow being cursed is part of the humor.
 
  
To assist the programmer, the comic gives an example of how to avoid the use of the number 3, by using a slightly convoluted method of using <code>int(pi)</code>, which means the {{w|integer}} part of {{w|pi}}, without the {{w|fractional part}}. Pi, an {{w|irrational number}}, has a value starting <code>3.14159...</code>, making <code>int(pi)</code> equal to 3. This is demonstrated in a formula to calculate the {{w|Sphere#Enclosed volume|volume of a sphere}}, normally (4/3)*pi*(r^3), but converted for avoidance of the number 3 to (4/int(pi))*pi*(r^int(pi)).
+
This comic tells a simple, deadpan joke: that the number "{{w|3 (number)|3}}" is cursed and thus should not be used in programming. [[Randall]] recommends that programmers instead use <code>int(pi)</code>, which means {{w|pi}} rounded to the nearest {{w|integer}}. Pi, an {{w|irrational number}}, has a value starting <code>3.14159...</code>, making <code>int(pi)</code> equal to 3.
  
For a number of reasons it is a good programming practice to use {{w|Variable (computer science)|variables}} and {{w|Constant (programming)|constants}} where a value is used in multiple places, however this is not typically used in the case of natural numbers. There are unusual situations where this type of programming is a valid method, however typically for more specific circumstances, and not a certain number being seen as cursed.
+
In the title text, Randall takes the joke a step further, suggesting the usage of {{w|floor and ceiling functions}}: <code>ceiling(pi)</code> would be pi rounded ''up'' to the next integer, which is {{w|4 (number)|4}}; and <code>floor(pi)</code> is pi rounded ''down'' to the next integer, which is 3. (Note that <code>int(pi)</code> and <code>floor(pi)</code> have the same value. <code>int(n)</code> will always be equal to either <code>floor(n)</code> or <code>ceiling(n)</code>.)
  
In the title text, Randall takes the joke a step further, suggesting the usage of {{w|floor and ceiling functions}}: <code>ceiling(pi)</code> would be pi rounded ''up'' to the next integer, which is {{w|4 (number)|4}}; and <code>floor(pi)</code> is pi rounded ''down'' to the next integer, which is 3. (Note that <code>int(n)</code> and <code>floor(n)</code> have the same value when <code>n</code> is greater than or equal to zero. For values less than zero, <code>int(n)</code> is equal to <code>ceiling(n)</code>.)
+
The joke here plays off of the fact that the intricacies of programming are endlessly confusing, and that [[292|novice programmers are often told to simply not do certain things without any explanation]]. Without knowing how a given programming language works, a new coder has no way of knowing which sorts of things are important to pay attention to. Randall takes this to an extreme here by suggesting that certain numbers could be inherently problematic, but the general idea is perfectly believable.
 
 
The joke here plays on the fact that basic rules of programming are confusing and novice programmers are often told to simply not do certain things without any explanation (see [[292: goto]]). This includes, in particular, a general proscription against "{{w|Magic number (programming)#Unnamed numerical constants|magic numbers}}" in the code. Replacing all significant magic numbers with named constants makes programs easier to read, understand and maintain. Randall takes this to an extreme by suggesting that certain numbers could be inherently problematic, but the general idea is perfectly believable.
 
 
 
[https://youtu.be/TT6UbrfETPc?t=17 ''Mmm... Floor pie.''] is a reference to The Simpsons.
 
 
 
See also {{w|Cargo cult programming}}.
 
  
 +
<i>Mmm... Floor pie.</i> is a reference to Homer Simpson [http://www.youtube.com/watch?v=GnjzmdxTXGQ]
 
==Transcript==
 
==Transcript==
:[Inside a frame a formula is shown:]
 
 
:volume(r) = (4/int(pi))*pi*r^int(pi)
 
:volume(r) = (4/int(pi))*pi*r^int(pi)
 +
:Programming Tip: The number "3" is cursed. Avoid it.
  
:[Caption below the frame:]
 
:Programming Tip: The number "3" is cursed. Avoid it.
 
  
 
{{comic discussion}}
 
{{comic discussion}}
 
[[Category:Programming]]
 
[[Category:Programming]]
[[Category:Geometry]]
+
[[Category:Math]]
[[Category:Comics with cursed items]] <!-- The single digit betwixt 2 and 4; One quarter of a dozen; Exactly half the number of toes you should have left if you first cut off one for each arm and leg you possess... -->
 

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)