Metasyntactic variables
If you're writing some toy code that doesn't do anything (e.g., it just demonstrates some syntax), there are obviously no meaningful names to give the variables and types in that code. What you need are words that are obviously meaningless, and obviously placeholders for the meaningful names that you'd use in real code.Of course there are no such words (except maybe "um" and "like" and the like), so the programming community has to invent a few and use them by convention. These are called metasyntactic variables; Wikipedia explains why they're called that, and some of the history. In other languages, they're usually called foo, bar, baz, and qux.
Python has its own unique set of metasyntactic variables, which are actual words, but words unlikely to appear in normal code. This has the advantage that the pattern can be extended in new ways and everyone will intuitively know what you mean. Except, of course, that you have to know the pattern.
Spam, eggs, cheese, beans, toast, and ham
Python is named after Monty Python, because Python's inventor, Guido van Rossum, is a big fan, like many computer geeks. "Spam" is one of Monty Python's most famous skits. Most of the words in the skit are the repetitive names of the heavily-spam-focused breakfast dishes on the menu, plus a group of Vikings singing a song about Spam. So, Python uses the ingredients of those dishes for its metasyntactic variables.Here's the menu:
- egg and bacon
- egg, sausage, and bacon
- egg and spam
- egg, bacon, and spam
- egg, bacon, sausage, and spam
- spam, bacon, sausage, and spam
- spam, egg, spam, spam, bacon, and spam
- spam, spam, spam, egg, and spam
- spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam, and spam
- lobster thermidor aux crevettes with a Mornay sauce, garnished with truffle paté, brandy, and a fried egg on top, and spam
So, you can see where the standard metasyntactic variables in Python come from.
Well, almost. Cheese, ham, and toast aren't even mentioned in the skit (although ham does appear in one of the silly names in the credits of the episode), and beans only appears once, while bacon and sausage are all over the place. So, why?
Back in the early 90s, we didn't have YouTube and t'Netflix. In them days, near 30 year ago, if we wanted to watch our favorite old shows, we were glad to find them on videotapes. Without subtitles. Or readable picture quality. Or, often, videotapes. And that was if you had a VCR. We never had a VCR, you used to have to spool the tape by hand and try to read it with a compass needle. If you were lucky enough to have hands, that is, we couldn't afford 'em. Still, we were happy in them days. We couldn't go to t'Wikipedia on t'World Wide Web to look up information we'd forgotten. We had t'Yorkshire Wide Web, which had nought but an ASCII art picture of a terrier, only it was in EBCDIC, mind, so you had to translate it by hand. We had to remember things for ourself. Except we were too busy remembering other people's things. Only job you could get back then. Paid thruppence a week, working 24 hours a day. Started when we were three years old and got our first lunch break at six. We'd get a crust o' stale bread and back to work for t'next three years. 'Course lunch break wasn't paid, we had to pay the owner to take the time off, then pay him to come back to work, but it was a living, and we were happy to have it. We could take the money home to our Dad and maybe he'd only kill us and dissolve our bones in acid once or twice before supper. You try and tell the young people of today that, and they won't believe you.
When you need a superclass of Spam, Eggs, and Cheese, or a class that has spam, eggs, and cheese members, you've got Breakfast, and sometimes Menu. Since none of these types have any obvious verbs associated with them, when you need to talk about methods, you'll occasionally see waitress.serve(spam) or song = [viking.sing() for viking in vikings].
Gouda and edam
Guido van Rossum comes from Holland. Not the Netherlands, the part of the Netherlands called Holland. Although he's also from the Netherlands. And he's Dutch, too. Maybe this is why the most famous line in the Zen of Python is "There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch."Gouda and Edam are two famously Dutch cheeses. So, when you need to create meaningless instances of a meaningless type in your example code, the type is usually Cheese, and the instances will be gouda and edam, because those are two famously Dutch cheeses. (If you need more, use some other Dutch cheeses. Just don't use griene tsiis or nayl tsiis, because those aren't really food, they're just something that Frisians invented so they can claim their language sounds like English.)
Tulips are also an important part of Dutch history, especially in the North Holland area that Guido is from. Most famously (if not accurately), the Dutch cornered the market on tulips and then created a speculative bubble that ruined their economy, which is what allowed the English to take over as the leaders of the financial world. So, obviously, that's what the prerelease version of the new asyncio library for Python 3.4 was called. But don't eat tulips, as they're mildly toxic and taste horrible.
Counting to four three
Sometimes, examples will be numbered 1, 2, and 4. Especially when someone's making a point about 0-based vs. 1-based indexing. This is a reference to the running joke in Monty Python and the Holy Grail, there's a running joke about Arthur having problems counting to three. In particular, the Holy Hand Grenade of Antioch scene has a biblical quote from Armaments 2:9-21:And the LORD spake, saying, 'First shalt thou take out the Holy Pin. Then shalt thou count to three, no more, no less. Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once the number three, being the third number, be reached, then lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who being naughty in My sight, shall snuff it.'There's also a joke from the Spanish Inquisition skit, where one of the cardinals is trying to enumerate the
Hungarian
"My hovercraft is full of eels" obviously needs no explanation; what might need an explanation is why translating from Hungarian would be relevant in programming.Hungarian notation, named for the famously Hungarian Xerox/Microsoft employee Charles Simonyi, means encoding the type of a variable into its name. For example, instead of having a variable "name" or "pos", you'd have "szName", which tells you that it's a zero-terminated string, or "rwPos", which tells you that it's a row rather than column position. Relatedly, in Perl and related languages, instead of "name" or "names" you'd have "$name", which tells you that it's a scalar, and "%names", which tells you that it's a hash (dictionary). In Python, none of this is considered idiomatic. If you need separate row and column positions, go ahead and call them "row_pos" and "col_pos", but don't try to come up with a standard "rw" abbreviation and apply it to all row variables whether needed for disambiguation or not. So, if you've translated sample code from (usually) Windows-specific C++ or Visual Basic to Python, and come up with a bunch of variable names like "szName", you've mistranslated from Hungarian.
This is usually a sign of a bigger and more general problem: Translating code at the line-by-line level from a very different language is almost always going to give you non-idiomatic, inefficient, unmaintainable code. This actually comes up more often nowadays with people trying to write Java code, or occasionally even Scheme/OCaml/Haskell code, in Python. But it's the same problem.
"My hovercraft is full of eels" is shorthand for both of these ideas. If someone says that as a comment on your code, it means your code doesn't look like Python.
Add a comment