"Begin at the beginning," the king said "and then go on till you come to the end, then stop.— Lewis Carroll - Alice in Wonderland
"Let's start at the very beginning, a very good place to start"— Julie Andrews - The Sound of Music
This was a lightning talk given at YAPC::Europe 2004 in Belfast, on 2004-09-17.
Lewis Carroll was a literary giant, writing (among other things) two works of great interest to programmers, "Alice in Wonderland" and "Through the Looking Glass". The questioning of meaning, and things like recursion and reflection abound. These stories find their echoes in modern-day programs like adventure and rogue, and MUDs in general.
Julie Andrews, on the other hand, is famous for bad haircuts.
What is this all about? It is the Lewis Carroll versus the Julie Andrews schools of programming style. What side are you on, and what of Perl?
This is a rant on start_ and end_ method names. Take another look at the quotes at the top of the page. For a computer language that prides itself on linguistics, semantics and idioms, how did we get this so wrong?
What is more, the situation for Perl 5 is probably hopeless, but maybe for Perl 6 there is something we can do.
The answer is that in spoken word, it hardly ever comes up. It's particularly prevalent in the computer field, but not in The Real World. Here are a few examples:
When Michael Schumacher climbs in his Formula 1 racing car, his main goal is to take pole position, and thus be in the car closest to the starting line. (Note we say starting line, not beginning line). Assuming all goes to plan, a bit over an hour later, he will be the first across the finishing line (not the ending line).
And at the start (ha!) of the race, the race marshal will say "Gentlemen, start your engines." (At least, once upon a time, they used to). So the drivers start their engines. And when the race is over, do they end their engines? It could be debated that some drivers do so during the race, but no, they don't end their engines, they stop them.
And more good advice: don't start something you can't finish.
So the heart of the matter is that start pairs up nicely with finish, or stop. It does not pair up with end. The opposite of end is... begin.
What is more, there is a long line of history of computer language that get this right.
From the Scandinavian school of programming, we have the venerable Algol and Simula languages that use begin/end pairs. There is another language named Leda that gets it right (but sadly, messes up badly by using curly braces to denote comments).
Begin/end blocks appear in Pascal, Modula-2, Modula-3, Oberon and other wirthy languages.
Obscure languages, like Cosy Infinity, Phantom, Sina XPL0 and Ada also use them, as does PL/0 (no relation to PL/1) and YAFL (which, I assume, stands for Yet Another Fucking Language).
Useful languages, like PL/SQL and VHDL also use them, as do AWK and, um... Perl.
In fact, Larry Wall went to considerable trouble to avoid using START as a keyword. We have BEGIN, INIT and CHECK. But no START.
Some examples of Perl modules include:
And that points to the way to fix the problem in Perl 5. You only need to:
*begin_table = *start_table
... more or less and thereby install an aliased method name. Instant fix.
I went Googlewhacking™ to get some statistics to bolster my argument. The results didn't draw the conclusion I would have liked to make.
| Terms | Page hits |
|---|---|
| start finish | 6 770 000 |
| start stop | 10 300 000 |
| begin end | 10 900 000 |
| start end | 15 900 000 |
| as of September 2004 | |
So my plea is this: when you start writing Perl 6 modules, spare a thought for Lewis Carroll and Julie Andrews, and ask yourself whether you want to begin at the beginning, or begin at the start.
Thank-you for listening.
Fri Sep 17 16:35:25 CEST 2004