Archive for June, 2010

GOTO considered helpful

June 24, 2010

How hard is Java?  Hard enough that Stanford CS students start by learning a baby version of it.

How easy is BASIC?  Easy enough that a child could pick up the essentials by looking in a book of BASIC computer games.

David Brin wrote an article a few years ago decrying the demise of BASIC.  What he didn’t say explicitly was that one of the reasons BASIC was so easy was its workhorse of control flow – the GOTO.

The BBC comedy show “Look Around You” opens with someone typing the lines:


20 GOTO 10


and then showing the spooling text.  A joke about computer programming on national TV!  And not one of those XKCD jokes, but one that everyone gets!

GOTO is the most natural statement possible.  A reasonable person might be puzzled by X = X + 1 or even a PRINT statement (do you print the ” as well?  What if you want to print a “?), but how can you misinterpret GOTO 10?  There’s a reason flowcharts and Choose Your Own Adventure books were so popular.

Now, I’m not so crazy as to recommend using BASIC for real programming.  If you’d had to debug a Fortran program with a nine line segment containing five GOTOs, you’d be wary of that too.  But it is a great language for learning programming – even the name and its expansion betrays its orientation towards beginners.

Remember, the most brilliant mathematicians and computer scientists took hundreds of years to come up with functions, objects, and structured programming.  An eleven-year old who’s confused about whether f(x) is a function evaluation or a multiplication has no chance with anything too complicated.  At that stage, just learning how to follow directions is considered a major achievement. Line numbers and GOTOs are perfect for this.

Couldn’t we do all this with a modern language like Python?  It’s a fine language, but, as Lloyd Bentsen might have said “Python, I programmed in BASIC.  I knew BASIC.  BASIC was a friend of mine.  Python, you’re no BASIC.”

Won’t we develop a bunch of programmers with bad habits?  No more so than crawling develops bad habits for running.  And so what if some kids use a few too many global variables.  A few code reviews will whip them into shape, and eventually they’ll put their GOTOs away, or maybe pass them on to some fifth-grader.  But they’ll have had them as training wheels to grow up with.


George Bernard Shaw, the Jack of Spades, and BP

June 1, 2010

Why would BP take the risk of a major disaster – one out of all proportion to the cost to avoid it?  The answer may lie in a combination of two jokes.

You may have heard George Bernard Shaw’s story where he asks a woman if she would sleep with him for a million pounds.  When she says yes, he asks if she would sleep with him for sixpence.  Outraged, she says “Certainly not!  What sort of woman do you take me for?”  “We’ve already established that”, he says, “Now we’re just haggling over price.”

In Guys and Dolls, Sky Masterson turns down a proposed bet, saying:  “Let me tell you a story.  When I was a young man about to go out into the world, my father says to me a very valuable thing.  ‘Son’, the old guy says, ‘I’m sorry that I am not able to bankroll you a very large start.  But not having any potatoes to give you, I am going to give you some very valuable advice.  One of these days in your travels, you are going to come across a guy with a nice brand new deck of cards, and this guy is going to offer to bet you that he can make the Jack of Spades jump out of the deck and squirt cider in your ear.  But, son, do not take this bet, for if you do, as sure as you are standing there, you are going to end up with an ear full of cider.’ ”

Conventional economic theory says that BP should invest in safety only up to a certain point – where the marginal benefit equals the marginal cost.  There is no point in spending another ten million in safety if it saves you only seven million in expected disaster costs.  Following this path leads you to risk management and profit maximization.

In practice, however, this turns out to be exactly the wrong approach – the probabilities cannot really be estimated, and you get sloppy and the Jack of Spades jumps out of the deck.  BP should have learned the lesson of the first story, and acted as if safety were its top priority, incomparable with any monetary benefits.  Exxon and Chevron learned this lesson the hard way, and now have an almost ridiculous obsession with safety (in the West, at least).  Of course, safety is never truly an oil company’s top priority – the oil is safest in the ground.  So this is a lie, but a noble lie, the sort that people tell themselves all the time.  And if you’re running an oil company, you should tell it to yourself all the time, until you come to believe it.  Because the alternative only gets you an ear full of cider, every time.