|Just another Perl shrine|
Litmus test: It's ok to roll your own if...by davido (Archbishop)
|on Sep 18, 2003 at 23:28 UTC||Need Help??|
This is not intended to be a list of why or why not to reinvent ones own wheel. Rather, it's a subset of talking points, a preliminary checklist to consider before one dives into the trouble of hand-coding something that's already been done. Consider these points that I weigh as I'm tinkering with code. These are talking points, not cut and dried criteria. As you conscienciously develop code, undoubtedly you will have your own barometers. But I think that these are valid and interesting points for consideration. Now for a little preaching to the choir:
It's ok to roll your own (in place of using a well-written module) when:
While many people are capable of rolling their own, and may even frequently do so when they have a specific need, those situations that require such treatment, I assert, are the exception, and not the norm. Of course for the purposes of this discussion, I refer to module with the meaning of "well-written, publically available (via CPAN or core Perl distribution) module".
What also seems to be the norm among many a beginner is the script-kiddy attitude that, "I know what I need, and I'll just plink out a few lines of code to do it; the module is overkill." What is really going on in this kiddy's mind is probably that he/she doesn't really care to wade through 5 minutes worth of POD to understand how the module works, and that he/she knows darn well that these six lines of code will fit his need. What is implicitly ignored by that person is all of the above list items.
Think about what an extensible tool the original formmail.pl would have been, for example, had it originally been written with 'use CGI'. As Lincoln released updates to CGI.pm, inspired by the feedback of many thousands of uses, a simple upgrade-installation of that module would import much of its improved security and robustness into the original kiddie's script, without even changing a thing in the original script. (Note: Lincoln has nothing to do with the original, poorly written formmail.pl, but has a lot to do with the well written CGI.pm). And those things that might be required to be changed (due to changes in the user-interface of CGI.pm) would force the author of formmail.pl to keep up with the state-of-the-art in CGI security.
I don't mean to pick on formmail in specific. It just happens to be a well-known example. There are plenty of lines of script-kiddie code out there that suffers from similar short-sightedness.
I'm certanly no expert on either rolling my own or using modules. I can say that when I use a module for something, I tend to get a better solution than when I don't bother with figuring out how to apply the module in question to my script.
There recently was a discussion on Usenet about "why should I use a module when I already know how to parse HTML". About two posts into the thread it became readily apparent that "already know how" was an overstated assertion. Modules are more than often developed by people who have a strong understanding of the subject matter. Modules are rigorously tested. Modules are used by a vast array of individuals, in a vast array of applications, and put to tests that no single author could ever forsee. And feedback rolls in, "This needs to be tweeked. That might be a security risk. This other thing might be more efficient coded as follows..." And those maintaining the module gain the benefit of feedback from many many end users, rather than only being able to rely on their own experience in refining the module.
With all this in mind, it seems to be a significant exercise in "misguided lazyness" (as opposed to the healthy sort of laziness that Mr. Wall promotes) to roll ones own rather than take 5 minutes away from the keyboard to learn how to use the time and real-world tested module.
I'm, of course, interested in hearing any comments to this discussion. It's possible that I've missed some points, made some incorrect assertions, or simply misunderstood some aspect of the subject. I'd like to hear what others think.
"If I had my life to do over again, I'd be a plumber." -- Albert Einstein