Sunday, 10 March 2013

normality has been restored...

...partially, anyway.

When my home machine died, and I upgraded to Windows 7, my incredibly ancient 16-bit Smalltalk/V would no longer work.  As this was what I used to generate the book review pages on my website, it was a bit of a disaster.

So over the past several weekends, I've been re-implementing my book list program, from scratch, in Python, and the new pages have finally gone live.  (There are still broken links from the non-automatically generated pages; I'll fix those next.)

This was my first major foray into Python.  Three years ago, I wrote my first ever Python program -- a Game of Life implementation, using Gosper's hashlife algorithm -- but then didn't touch it again until recently.  Instead, I was using Matlab for all my number-crunching needs.  However, I needed something a bit more friendly for teaching some non-computer science students a little bit about simulation.  So before Christmas I wrote a small flocking program in Python, and a few little bits and bobs.  Then I learned about NumPy, which does a lot of the matrix stuff that Matlab does, so I thought I'd give it a try, by reimplementing some Random Boolean Network code I'd originally written in Matlab.

I was really impressed, so decided to do some more NumPy programming, to learn it better.  I wrote a few programs to support some practicals for a module I teach: a quantum random walk simulator, an iterated function system, and a 1D cellular automaton.  And after that exposure, I decided I was deeply in love with Python.

But the book list program is my biggest yet, by a long way.  All the previous programs had a core of essentially about 10 lines of code (each of those lines doing a lot, mind you!), each written in an hour or so.  The book list program is several hundreds of lines (many of which also do rather a lot), split over 5 files and several classes.  I also decided to take the opportunity to reorganise and tidy up the structure of my web pages, which involved writing a few utilities, to rename a bunch of files, to write a new table in the database, that sort of thing.  File handling. Database access. All amazingly simple in the marvellous language that is Python.

Although, frankly, I couldn't have done it without the wonderful Stackoverflow forum.  The Python documentation is useful if you know how to do something, and just need to check the syntax or method name.  It's not so helpful if you don't know how to do something. And Python has its own way of doing things.  But every time I typed into Google: "python how to  XXX", for a wide range of XXX, there was Stackoverflow with the answer -- often several answers!  Thanks, guys.

When I started writing this, I was consulting online resources for nearly every line.  But now, I'm happily typing things like
reviews = [bk for bk in have_reviews if bk.isNFBook()][0:10]
without looking things up any more.

And I'm now looking round for my next Python project...

No comments:

Post a Comment