Date: Aug 28, 2005 2:39 PM
Author: Kirby Urner
Subject: On "Programming the Calculator" (a curriculum segment)

By "programming the calculator" I don't mean taking up a calculator and programming it by entering into its memory using its keypad.  I mean starting with a computer and emulating a calculator by programming a GUI window object, with the calculator its content.

This "shop class" approach to building a calculator will drive a review of what all the keys do on a real (non-emulated) calculator. I just explained SIN and COS to my daughter, after she tutored me in 'Majesty' (a computer game she likes, and I respect for its quality craftsmanship -- and won at this morning). I did this to demystify a new keyboard; the school requires middle schoolers carry these devices. I think if you carry it, you should know what the keys do, even if you don't need them yet. I bought her a Sharp EL-501W at the local grocery (returned the rebate slip, with all requisite documentation).

Later, once you've been over the key functions, you get to see how a programmer wires up screen buttons so that mouse clicks fire off to subscribers, who respond to button press events. A number is keyed in and registered. An operation key is queued. Another numeric argument is keyed, and the equals key pressed. This triggers a cascade of evaluations leading to a result, which must be communicated to the emulated LED (just pixels on a computer screen).

Exactly how deeply a teacher chooses to go in this direction is a variable. Some trade school community college course for GUI programmers might go into it for a whole semester. In another context, a mere allusion to this project might suffice. An advantage of this proposal is it has already been done. Numerous published works already implement the GUI calculator, using this or that computer language. In other words, we're talking about a genre, the literature is already big, the teacher doesn't have to invent a syllabus from nothing.

A contribution to this genre came at OSCON 2005, in Jim's IronPython demo, where a calculator was displayed using the Avalon library. Miguel asked to see the buttons all tilted at 45 degrees, a ridiculous expectation for a real calculator, but a request completely consistent with the Avalon API, and therefore IronPython's. Jim obliged with some list comprehension (one line of Python). The experiment was a success. The appeal of .NET and Mono technology had just been bumped up a notch.