Small Elegant Pieces

OK, I think I’m learning something about how to manage my limited amount of skill and time to do leisure-time programming for myself.  “Bottom-up programming” is important.

I just decided to do a little gallery app for the umpteenth time; in PHP.  I know PHP well enough that I don’t trip over the big gotchas too much, and I know where in the documentation to look to find the functions I need.  It’s also dead easy to deploy (“put the PHP file where your web browser can find it.”)

Following impulse, I decided to do this all at my own pace, and in small, elegant pieces.  I first learned about the power of tiny, elegant functions and methods when I was learning Smalltalk, and my frequent mistakes sent me into its debugger, which often, to my surprise, took me into the guts of the code of Smalltalk itself.  Looking at the way Smalltalk itself was written, I found that one- or two-line-long methods weren’t at all uncommon.

The idea there is that methods, functions, whatsoever serve the purpose of conceptual chunking.  And the smaller the chunks, the easier they are to manipulate.  Ideally by looking at the name of the method, you will know exactly what it does.  So when it’s used in the code, it documents itself.

I don’t get to do that too much at work. 100-line functions which do three dozen things are the order of the day, and it’s usually not within the scope of what I’m doing to break them apart at all. So when I can actually do that kind of programming, it’s kind of fun.

Oh, where was I? Yeah.  So I decided, for this little bit of coding, to do everything in small chunks that I totally understood. And I had a heck of a lot of fun, and I ended up with a nice little thumbnail-maker and that sort of thing. There’s not much to it yet, but if I keep working on it, which I might, I’ll end up with my own personal version of the dozens of little-PHP-gallery-makers out there.

And I actually enjoyed it, and it wasn’t intimidating or wearying. I’m proud of the code that resulted.

Taking things a very small, doable chunk at a time is peaceful and pleasant. It’s one good way to be creative.

Maybe some of the programming things that intimidate me intimidate me because I try to take on too much at once, and don’t do it piece by piece, making sure every small piece is well within my ability and attention span.

Hey I think I’ll make a quick app.

I want to make my own rss reader.  Let’s get started!  I’ll do it in wxpython.  Hm.  The built-in wxpython on OS X doesn’t work anymore since I upgraded Python.  I’ll install a new one.  It fails; errors out.  OK, I’ll try wxruby.  Easy to install — just a rubygem.  Installing… and it fails.  How about Shoes?  I used to make lots of fun little applications with Shoes. Eh, ever since _why disappeared I can’t bear to mess with his former projects. I know people are continuing developing it, but I don’t care.  _why’s gone, no Shoes.  What next?  Maybe a locally-powered webapp? How bout Sinatra?  Easy to install; simple in concept.  Install it; make it go “Hello World.”  OK, now I’ve got to… to… come up with a user interface from scratch using only HTML, with Javascript for immediate interactivity but Ruby when that interactivity passes an arbitrary threshold and interacts with the “server.”  *sigh*.

You know, NetNewsWire is pretty nice.