Clear questions and runnable code
get the best and fastest answer
Reinvent the wheel!by telemachus (Friar)
|on Mar 21, 2009 at 15:55 UTC||Need Help??|
Well, sometimes at least...
I'm posting this as a way of thinking something through and getting some feedback. The advice in the title is really for me, not completely general, but I think it makes sense more often that some folks seem to think
First an overview of the playing ground:
So, what's this got to do with reinventing the wheel, you ask? Answer: I believe that one way for me to learn is to reinvent the wheel, and that's what I've been doing for the last week. I had a breakthrough this morning, and this is the post too-much-coding debrief. I want to justify this to myself and see what others think.
Quick background. I'm a teacher and part-time sysadmin at a school. My primary job is teaching, but I also administer one of our internal servers. I do this because we are a Mac shop, and I'm the only one there who is comfortable at the command line. The server I administer hosts blogs, a school-wide wiki and is testing Moodle. We started with the wiki and one blog. We now have 65 blogs, the wiki and the test Moodle installation. Bully for us. However, 65 blogs require a lot more babysitting than one. Most of my coding is for and about the blogs: keeping track of them (versions, administrators, database titles, etc.), patching and upgrading them, backing them and their databases up regularly, updating them. Over the last year, I've written about 4,000 lines of code, mostly in Perl, to help me do all this. (Sloccount says that's about 2.5 person-months worth of code, which kind of hurts, but what are you going to do?)
I joined PerlMonks a few months after I started to learn Perl, which means I've been writing code for about a year and a half. I have zero background in CS. I came to all of this sideways (started using Ubuntu, then Debian in 2006). I've read Beginning Perl, Learning Perl, Intermediate Perl and quite a lot of the documentation in perldoc. I took an Introduction to C class at a local college on the weekends.
Early on, I learned the lesson that using other people's code is a Good Thing (TM), and up until recently, I've done just that.
Recently, however, I've begun to have my doubts. Working the way I have been, I ended up writing the same sorts of (reasonably basic) things over and over while letting more mature modules do the "heavy lifting." In one sense, that's obviously smart: they write much better code than I would, even if I had the time to write the whole lot of it (which I don't). But - and here's the kicker - I want to learn more. If I keep going the way I have been, I never will.
Luckily, I'm on vacation (ah, the life of a teacher) and my wife's out of the country, so the last week, I decided to write my own version of File::Find plus a custom pretty printer for it. It's primitive as hell, lacking most every feature you might want, and I still had to steal most of the ideas from Intermediate Perl and Higher Order Perl. Later today when I start to look at the guts of File::Find, I will probably feel very stupid about my choices. (I deliberately didn't look up until now, which is kind of silly considering how much I stole from Schwartz, foy, Phoenix and Dominus.)Nevertheless, it bloody works. It's even nicely decoupled: the main routine lives in a module, you feed it callback routines in the calling script, and it's easy to customize to produce a variety of reports. (It's first job is to tell me just who is uploading all those f@$#king .ppt files to the damn server.) Although I could have done this in a tenth the time with File::Find, I feel that I've learned more in this one week than in all the rest of the previous year. Callbacks and coderefs finally make (some) sense to me, and I'm starting to get a sense for how and when to use recursion, when and how to build a complex data structure, when to process individual items immediately as you go. (You can't group all the files in one directory (or sub-sub directory) and then sort them by size & then name if you've already printed them. But sometimes, you just want the list without any further sorting or processing needed. If you take these two functions apart, you can choose when to do it one way or the other. Obvious, but only after you see it.)
Anyhow, this has been too long and rambling. My point is this: I reinvented the wheel, probably poorly and with far too much effort, but I did it and I'm glad I did. I plan to do it again this summer when I have more free time. If you're still reading, and you think I'm barking up the wrong tree, please let me know.