GO TO XO

On the XO Laptop

Python-XO: On the shortest Python program

with one comment

As reported in Caduceus Redux, Robert Bolgar says, “Maybe I should gear up my brain to learn some Python, too. About time I woke up to the computing world.”

I write this note to Josh and Zander Bolgar to provide a suggestion on how to help Dad wake up to the world of computing. Other members of the XO Generation may find it a way to help start their parent’s education on programming as well.

One of the most common sources of error in writing in a program is the failure to properly deal with what are known as “edge cases.” For example, running a loop once too often, or failing to run it far enough.

A further example is whether the program properly deals with the “null,” or empty case.

Since Python is based on set theory, let’s see if the Python compiler handles the case of null input properly. Linux provides many useful features, among them a perpetual source of nothingness in the form of a special device known as “/dev/null”. It appears as a file, but whenever you try to read it you get only the end-of-file signal. There is no data in that file save its end.

The question then is what happens when you execute:

$ python shortest and longest sentences in natural language, in which a letter consisting of a single character (“!”) communicated a meaningful message. But Python is even better in that you can write a correct program by writing a program with no characters at all!

Zander and Josh can thus start their dad on his programming career by just having him execute the empty Python program.

If is of course much more fun to write programs that are longer and do some useful work, as I will try to show in future posts in this series. But education in any subject, including programming, must begin with a first step, even if it is just to show that “nothing ventured can still some education gain.”

Advertisements

Written by daveshields

December 19, 2007 at 6:57 pm

Posted in xo-laptop

One Response

Subscribe to comments with RSS.

  1. […] is a trick question, in that we are asking about what I think is an empty set. See Python-XO: On the shortest Python program. Since no commercial product has had that much effect, then Linux is as good as any of them. So the […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: