Types
Types
[Caption above the black part of the comic:] My new language is great, but it has a few quirks regarding type:
[The rest of the comic is written in a black rectangle. All text to the left of ">" is written in gray. Text to the right of the ">" on the lines with numbers are in white, and then gray text on the other lines. There seems to be a missing ">" after line no. 3.] [1]> 2+"2" => "4" [2]> "2"+[] => "[2]" [3] (2/0) = > NaN [4]> (2/0)+2 = > NaP [5]> "" + "" = > ' "+" ' [6]> [1,2,3]+2 = > False [7]> [1,2,3]+4 = > True [8]> 2/(2-(3/2+1/2)) = > NaN.000000000000013 [9]> Range("   ") = > (' " ',"! "," ","!",' " ') [10]> + 2 = > 12 [11]> 2+2 = > Done [14]> Range(1,5) = > (1,4,3,4,5) [13]> Floor(10.5) = > | = > | = > | = > |_ _ _10.5_ _ _

This comic is a series of programming jokes about a ridiculous new programming language, perhaps inspired by Mathematica and Wolfram Language — the latter was used by Randall many times before. Maybe it's also inspired by Gary Bernhardt's CodeMash 2012 lightning talk on JavaScript's unpredictable typing. In the talk, the highly technical audience was unable to correctly guess the results of adding various JavaScript types and roared with laughter when they were revealed. The programming language shown in this comic has types even more unpredictable than JavaScript.
Most regular programming languages distinguish types, e.g. integers, strings, lists… all of which have different behaviours. But for instance, the operation "+" is usually conventionally defined over more than one of these types. Applied to two integers, it returns their sum.  Applied to two strings (denoted by being enclosed in quotes) it concatenates them:
While these behaviours are standard, conventional, and intuitive, there is a huge amount of variation among programming languages when you apply an operation like "+" to different types. One logical approach is to always return an error in all cases of type mixing, but it is often practical to allow some case mixing, since it can hugely simplify expressions. Variation and lack of a clearly more intuitive behaviour leads some languages to have weird results when you mix types.
Weird results abound in the new XKCD programming language:
The title text contains three further examples relating to color. color.rgb("blue") returns the hexadecimal code for pure blue (as would be used in HTML, for example), which is how a real programming language might work. The lookup for "yellowish blue" returns "NaN" (Not a Number) again, which makes sense at one level because there is no such color as "yellowish blue" (yellow and blue are opposites on the RGB color triangle , making yellowish-blue an impossible colour , which can only be perceived with great difficulty through contrived figures). However a more typical result would have been a failure indicating that the color database does not include the name, in the same way that a typo such as "bluw" would. (Note that HTML does explicitly attempt to handle all "color names". For the record, "yellowish blue" is a dark blue with an imperceptible amount of red — #0E00B0 .) Similarly sorting the colors would normally produce some defined ordering, such as alphabetical, but in this language it generates the string "rainbow". It seems that Randall's new language understands color theory in an unusually deep way.
[Caption above the black part of the comic:] My new language is great, but it has a few quirks regarding type:
[The rest of the comic is written in a black rectangle. All text to the left of ">" is written in gray. Text to the right of the ">" on the lines with numbers are in white, and then gray text on the other lines. There seems to be a missing ">" after line no. 3.] [1]> 2+"2" => "4" [2]> "2"+[] => "[2]" [3] (2/0) = > NaN [4]> (2/0)+2 = > NaP [5]> "" + "" = > ' "+" ' [6]> [1,2,3]+2 = > False [7]> [1,2,3]+4 = > True [8]> 2/(2-(3/2+1/2)) = > NaN.000000000000013 [9]> Range("   ") = > (' " ',"! "," ","!",' " ') [10]> + 2 = > 12 [11]> 2+2 = > Done [14]> Range(1,5) = > (1,4,3,4,5) [13]> Floor(10.5) = > | = > | = > | = > |_ _ _10.5_ _ _
