My daughter has been sounding out words for a while now, and in the last couple of weeks has gone from c-a-t to “B-os-ton” (as in “Boston Pizza”). A couple of days ago, she was struggling with a new word: eff, are, eye, ee, en, dee — we’ve taught her that when two vowels are together, the first one says its name, so she pronounced it to rhyme with “blind”. “Close,” I told her. “It’s ‘friend’ — in this word, the second vowel says its name.” She wrinkled her nose and said, “That’s not fair.”
She’s right: the “rules” of English spelling aren’t fair. Neither, unfortunately, are the rules of many programming languages. For example, suppose I tell you that:
4 * "5" => 20
i.e., that using ‘*’ on the integer 4 with the string containing digit ‘5’ is the integer 20, because the string is automatically converted to a number. What would you guess the result of:
4 + "5"
|4 * "5"||20||"5555"|
|4 + "5"||9||illegal|
That’s really what we mean by “fair” or “unfair” in this context: how easy is it to remember the rule(s) and predict what’s going to happen in new situations. Several tons of cognitive science research have shown that people are pattern matchers, not memorizers; our brains perform much better when applying a small number of general (i.e., consistent) rules than when trying to figure out which of a larger set of rules to use. Putting it another way, the shallower the decision tree, the faster and more correctly we solve problems.
This is why we switched from Perl to Python in the early days of the Software Carpentry course. Back in 1998-99, Python was still very much a niche language: going by Amazon.com book rankings, we figured it had about a tenth of the user base of Perl. But every single page of the O’Reilly pocket guide to Perl contained one or more of the words “except”, “unless”, or “however”, which meant that when we taught it, we kept having to say, “It’s usually like this, but sometimes like that.” Python was more regular, so material that had taken three days to cover in Perl only took two days in Python, and retention was higher (both immediately afterward and six months later).