If you look at Python tutorials and sample code, proposals for new language features, blogs like this one, talks at PyCon, etc., you'll see spam, eggs, gouda, etc. all over the place. Why?

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 one two three four diverse chief weapons of the Inquisition.

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.
0

Add a comment

Hybrid Programming
Hybrid Programming
5
Greenlets vs. explicit coroutines
Greenlets vs. explicit coroutines
6
ABCs: What are they good for?
ABCs: What are they good for?
1
A standard assembly format for Python bytecode
A standard assembly format for Python bytecode
6
Unified call syntax
Unified call syntax
8
Why heapq isn't a type
Why heapq isn't a type
1
Unpacked Bytecode
Unpacked Bytecode
3
Everything is dynamic
Everything is dynamic
1
Wordcode
Wordcode
1
For-each loops should define a new variable
For-each loops should define a new variable
4
Views instead of iterators
Views instead of iterators
2
How lookup _could_ work
How lookup _could_ work
2
How lookup works
How lookup works
7
How functions work
How functions work
2
Why you can't have exact decimal math
Why you can't have exact decimal math
2
Can you customize method resolution order?
Can you customize method resolution order?
1
Prototype inheritance is inheritance
Prototype inheritance is inheritance
1
Pattern matching again
Pattern matching again
The best collections library design?
The best collections library design?
1
Leaks into the Enclosing Scope
Leaks into the Enclosing Scope
2
Iterable Terminology
Iterable Terminology
8
Creating a new sequence type is easy
Creating a new sequence type is easy
2
Going faster with NumPy
Going faster with NumPy
2
Why isn't asyncio too slow?
Why isn't asyncio too slow?
Hacking Python without hacking Python
Hacking Python without hacking Python
1
How to detect a valid integer literal
How to detect a valid integer literal
2
Operator sectioning for Python
Operator sectioning for Python
1
If you don't like exceptions, you don't like Python
If you don't like exceptions, you don't like Python
2
Spam, spam, spam, gouda, spam, and tulips
Spam, spam, spam, gouda, spam, and tulips
And now for something completely stupid…
And now for something completely stupid…
How not to overuse lambda
How not to overuse lambda
1
Why following idioms matters
Why following idioms matters
1
Cloning generators
Cloning generators
5
What belongs in the stdlib?
What belongs in the stdlib?
3
Augmented Assignments (a += b)
Augmented Assignments (a += b)
11
Statements and Expressions
Statements and Expressions
3
An Abbreviated Table of binary64 Values
An Abbreviated Table of binary64 Values
1
IEEE Floats and Python
IEEE Floats and Python
Subtyping and Ducks
Subtyping and Ducks
1
Greenlets, threads, and processes
Greenlets, threads, and processes
6
Why don't you want getters and setters?
Why don't you want getters and setters?
8
The (Updated) Truth About Unicode in Python
The (Updated) Truth About Unicode in Python
1
How do I make a recursive function iterative?
How do I make a recursive function iterative?
1
Sockets and multiprocessing
Sockets and multiprocessing
Micro-optimization and Python
Micro-optimization and Python
3
Why does my 100MB file take 1GB of memory?
Why does my 100MB file take 1GB of memory?
1
How to edit a file in-place
How to edit a file in-place
ADTs for Python
ADTs for Python
5
A pattern-matching case statement for Python
A pattern-matching case statement for Python
2
How strongly typed is Python?
How strongly typed is Python?
How do comprehensions work?
How do comprehensions work?
1
Reverse dictionary lookup and more, on beyond z
Reverse dictionary lookup and more, on beyond z
2
How to handle exceptions
How to handle exceptions
2
Three ways to read files
Three ways to read files
2
Lazy Python lists
Lazy Python lists
2
Lazy cons lists
Lazy cons lists
1
Lazy tuple unpacking
Lazy tuple unpacking
3
Getting atomic writes right
Getting atomic writes right
Suites, scopes, and lifetimes
Suites, scopes, and lifetimes
1
Swift-style map and filter views
Swift-style map and filter views
1
Inline (bytecode) assembly
Inline (bytecode) assembly
Why Python (or any decent language) doesn't need blocks
Why Python (or any decent language) doesn't need blocks
18
SortedContainers
SortedContainers
1
Fixing lambda
Fixing lambda
2
Arguments and parameters, under the covers
Arguments and parameters, under the covers
pip, extension modules, and distro packages
pip, extension modules, and distro packages
Python doesn't have encapsulation?
Python doesn't have encapsulation?
3
Grouping into runs of adjacent values
Grouping into runs of adjacent values
dbm: not just for Unix
dbm: not just for Unix
How to use your self
How to use your self
1
Tkinter validation
Tkinter validation
7
What's the deal with ttk.Frame.__init__(self, parent)
What's the deal with ttk.Frame.__init__(self, parent)
1
Does Python pass by value, or by reference?
Does Python pass by value, or by reference?
9
"if not exists" definitions
"if not exists" definitions
repr + eval = bad idea
repr + eval = bad idea
1
Solving callbacks for Python GUIs
Solving callbacks for Python GUIs
Why your GUI app freezes
Why your GUI app freezes
21
Using python.org binary installations with Xcode 5
Using python.org binary installations with Xcode 5
defaultdict vs. setdefault
defaultdict vs. setdefault
1
Lazy restartable iteration
Lazy restartable iteration
2
Arguments and parameters
Arguments and parameters
3
How grouper works
How grouper works
1
Comprehensions vs. map
Comprehensions vs. map
2
Basic thread pools
Basic thread pools
Sorted collections in the stdlib
Sorted collections in the stdlib
4
Mac environment variables
Mac environment variables
Syntactic takewhile?
Syntactic takewhile?
4
Can you optimize list(genexp)
Can you optimize list(genexp)
MISRA-C and Python
MISRA-C and Python
1
How to split your program in two
How to split your program in two
How methods work
How methods work
3
readlines considered silly
readlines considered silly
6
Comprehensions for dummies
Comprehensions for dummies
Sockets are byte streams, not message streams
Sockets are byte streams, not message streams
9
Why you don't want to dynamically create variables
Why you don't want to dynamically create variables
7
Why eval/exec is bad
Why eval/exec is bad
Iterator Pipelines
Iterator Pipelines
2
Why are non-mutating algorithms simpler to write in Python?
Why are non-mutating algorithms simpler to write in Python?
2
Sticking with Apple's Python 2.7
Sticking with Apple's Python 2.7
Blog Archive
About Me
About Me
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.