Wednesday, March 26, 2014

Mike the Pythoneer...

A few weeks back my old Mac Mini got to the point where it was giving me the "gray screen of death" every 18 to 36 hours [1].  Replacing the RAM -- failing RAM being the most frequent cause of kernel panics -- didn't fix the problem.  I decided that six-and-a-half years was a good run, that I had outgrown the RAM size limit, that having a graphics chip too dumb to support acceleration for OpenGL wasn't good, and that having no OS upgrade path for the old machine was a bad thing.  So I got a new Mini.  It has not been an entirely painless process, largely because there have been a bunch of changes in the Apple development tools.

I have a couple of pieces of software that I use regularly that I wrote in Perl.  I'm entirely dependent on one of them, a note-taking application that also acts as the front-end for (sort of) organizing a whole collection of files of various types -- PDFs, images, old source code -- that is pretty static these days [2].  Another one, that is part of a package for drawing cartograms, is under off-and-on development.  Both were broken under the default Perl/Tcl/Tk that comes as a standard part of the new OS X, and required some effort to get running again.  To get the note-taking app running I ended up downloading and using ActiveState's Perl instead of the Apple default.  At one point in the past I had toyed with the idea rewriting the note-taker in Python (for other reasons) and had some code that tested all of the necessary GUI functionality; that old Python code ran on the new Mini with no problems using the Apple default installation.

Reading a variety of Internet things led me to (perhaps erroneously) conclude that: Apple is moving away from Perl and towards Python for scripting; Tkinter is a required part of the Python core, but Perl has no required GUI module; so Apple is more likely to keep the chain of Python/Tcl/Tk working in the future.  Suddenly, switching to Python seemed much more compelling than before.  I also came across Eric Raymond's old "Why Python?" article from the Linux Journal.  His experience seemed to match my own recollections of writing that little Python program related to the note-taker: I got over the "eeewww" thing about the use of white space to identify block structure fairly quickly, and I seemed to be writing useful non-toy code fairly quickly.

One of my favorite (and I use that word with some ambiguity) time-wasters on my computer is FreeCell.  Since Windows 95, Microsoft has always provided a simple version of the game as part of the standard distribution.  When I switched to a Mac at home several years ago, the lack of a simple free reasonably-attractive version of the game grated on me [3].  I ended up using a Javascript version in my browser, but recently that one began to act flaky, putting up placeholders instead of images for some of the cards.  "Two birds with one stone," I thought.  "Practice Python and get a version of FreeCell that looks and behaves like I want."

The good news is that with a couple of manuals open in browser tabs, writing the game went quickly.  Call it 15 hours total over three days to go from nothing to something that my fingers are almost comfortable with up and running.  And by nothing, I mean just that: no cardface images, no thoughts on data structure.  A blank slate.  Some of that time was doing small sorts of rewriting, when I would find an example that showed a better Python idiom.  The bad news comes in several parts:
  • There's a version of FreeCell that my fingers know just sitting there on the desktop now, begging to be "tested".
  • Feature creep is going to be an issue.  It should have undo.  It should have the ability remember the current layout and return to that.  It should have a built-in solver that works from any position.
  • It should run on my old Linux laptop.  It should run on my Android tablet.  It should run on my wife's iPhone (well, maybe that's a stretch).
So I guess I'm going to be a Pythoneer (I actually think "Pythonista" sounds better, but that's been preempted as the name of a commercial application).  Expect an occasional update on how things are going...


[1]  In the event of certain kernel panics, Mac OS X puts up a translucent overlay to block the display, along with a dialog box that says "You have to restart your machine" in several languages.  Until recently, I had no idea that such a thing even existed.  For the record, since it no longer has to support nearly as many processes, the old Mini has been up without a problem for more than three weeks.

[2]  At last count, a few hundred pages of notes and more than 100M of images, PDFs, etc.  As to why write my own when there are dozens of note-taking applications out there, let's just say that I'm an old geek and paranoid and don't like to have critical data stored in a proprietary file format.

[3]  I'm sure that all of the authors of the solitaire packages out there think their games are laid out attractively.  I just happen to disagree.

No comments:

Post a Comment