Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Use of Modules

by Kozz (Friar)
on Mar 25, 2000 at 03:54 UTC ( #6134=perlquestion: print w/replies, xml ) Need Help??
Kozz has asked for the wisdom of the Perl Monks concerning the following question:

I taught myself perl over the course of the last two years or so, and have certainly picked up some bad habits, though I try to write my programs as cleanly as possible. One thing that I sometimes have difficulty with is getting & using modules.

Part of the reason I try to write code to work without modules is because I want my code to be as portable as possible, without having to nag the administrator to install this package or that... (I'm a web developer of course). For example, rather than using LWP for things like retrieving webpage source or extracting links, I have a habit of re-inventing the wheel and writing subroutines that will do the same thing. (i.e. using use Socket and talking to a port instead of using the LWP module)

So here's my question:
Do any of the more "seasoned" perl programmers find my "anti-module" habits are a good thing? Or am I just creating more work for myself? If I write something in 20 lines that could have been written in 2 with use of a Module, am I creative, or am I stubborn?

Replies are listed 'Best First'.
Re: Use of Modules
by japhy (Canon) on Mar 28, 2000 at 12:25 UTC
    I use modules often. I rarely use a module I don't understand, though. Hey, it got me to learn a lot about sockets -- I realized the LWP bundle would do the job of the socket nonsense, but I wanted to make sure I knew what that nonsense was. If you think you can make a portable program without using modules, you're doing one of the following:
    • making a program that isn't meant to be ported
    • making a simple program that really needn't rely on complex operations, and therefore complex modules
    • making a mistake somewhere
    That doesn't mean you can't make something better than a module that is out there already -- but it's not likely. It is more than easy to write a crummy CGI query parser that "gets the job done" when the job consists of reading the query string from a GET query. But then you might need to add support for POST, and then come file uploads. And you probably didn't read the RFC on how query strings can be formatted. It's also easy to do a crummy job of parsing HTML tags.

    If I seem condescending or rude, I apologize, but I've had to argue my point several times. Not using a module because it's not in the standard distribution is no excuse -- if a sysadmin is not competent enough to install a Perl module, then they don't know how to use gzip, tar, and make. That is very sad. Or, if they are stingy, and won't do it, you can install the module in a local directory.

    There's a reason there are so many modules. There's a reason they come with their source and documentation.
Re: Use of Modules
by setantae (Scribe) on Mar 25, 2000 at 03:58 UTC
    Hmm, if you stick to standard modules then you shouldn't have a problem, as they're provided with perl (ie if you've got perl then you've got the module).
    So I'd have to say that I'd rather use a module..(although there's certainly a sense of satisfaction to be gained from doing it yourself).|setantae|

Re: Use of Modules
by chromatic (Archbishop) on Mar 25, 2000 at 05:30 UTC
    It really depends on what you're building... there's certainly nothing stopping you from dissecting a module, copying the relevant sections, and putting them in your own programs. (This providing both benefits -- a high-quality implementation, tested by hundreds of other smart Perl hackers, and portability).

    Don't stay away from the core modules, though! They're in the core for good reason!

Re: Use of Modules
by lhoward (Vicar) on Mar 26, 2000 at 23:54 UTC
    I firmly believe in the use of modules. I think that CPAN and the free and easy availability of Perl modules is one of the key features that sets Perl apart from just about any other language out there. I also think that CPAN is the only large-scale successful example of code reuse out there. CPAN has made the dream of software enginering code reuse a reality. If I can find a module that will do what I need, I will almost always use it. Perl modules also tend to be very clean (bug-free), mainly because of the large amount of "free testing" that they get. I see no reason to re-invent the wheel unless I have a good reason.
RE: Use of Modules
by orthanc (Monk) on Mar 25, 2000 at 20:54 UTC
    Modules are great, why re-invent the wheel especially when you want to create an app quickly. Someone else has usually wrote what u need. Creating your own modules also make your code look a helluva lot clearer. You needn't worry about installing the modules too, simply place them somewhere u have priviliges. Then use a BEGIN statement. BEGIN { push( @INC, '/path/to/module'); }; :)
Re: Use of Modules
by btrott (Parson) on Mar 25, 2000 at 04:54 UTC
    Seconded. LWP is a very standard module, so in that example there's really no reason to go on reinventing any wheels. Particularly since most of the modules I use, at least, are very standard and well-known indeed--off the top of my head, the modules I find myself using most often are CGI, LWP, DBI, and XML::Parser. Pretty standard, all.

    As for you saying that you have difficulties "getting" modules--what do you mean, exactly? You mean in terms of getting sysadmins to install the modules? Have you thought about setting up your own module area (that you'd own and control), then installing modules into that? The whole module installation thing is really quite easy with the CPAN module.

    Just some thoughts.

Re: Use of Modules
by turnstep (Parson) on Mar 26, 2000 at 00:06 UTC
    I vote creative. I don't like the argument of "re-inventing the wheel". While you shouldn't spend weeks beating your head against a wall, doing it yourself and THEN looking at the module is a great way to increase your mastery of the langauage, and of programming skills in general. There is always more than one way to do it :). After doing it yourself, you can look to see how a module does it, and perhaps learn something new. You may be happily surprised to see it is almost identical to your way of doing it. You may learn a great insight. In most cases, the module will work at least as well as your code, and probably better. However, you may decide to keep yours, or just "steal" parts of the module, to make your code smaller, or faster, or easier to read, or whatever your goals are. Modules allow for a quick and easy solution, but try it yourself first to learn more.
RE: Use of Modules
by Anonymous Monk on Mar 25, 2000 at 05:01 UTC
    I've always found it useful to program for the least common denominator. If you look at the adduser/deluser scripts for billing companies like IBill, CCBill, etc, none of them use modules. Why? Because their presence and usefulness often depends upon the competence of the administrator. I use modules whenever I have control of the server. When I code for portability, I stay away from modules as much as possible.
Re: Use of Modules
by ishamael (Beadle) on Mar 26, 2000 at 06:59 UTC
    i rather dislike most modules. i agree that if it is a standard module, like LWP: USE IT!, but if its something off the wall that i just need for one sub-routine im just as likely to write it myself. this is predominatly because i hate downloading and attempting to compile modules, especially when they themselves require other modules... its just tedious and annoying. if i know how to do it myself, i will. charlie schmidt
Re: Use of Modules
by Anonymous Monk on Mar 25, 2000 at 11:18 UTC
    What you are going through is an EXTREMELY common thing... Almost everyone goes through it at the beginning... I am not, by any means an "expert" programmer, but I can tell you that you there are only two good reasons to write your own code instead of using accepted modules: 1. You can do a better job 2. You want to learn how it is done. The problem with writing your own modules to replace existing ones is that you could be spending that time studying more advanced topics(or other modules). It is perfectly fine with me if you never progress any further, personally I don't need the competition. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://6134]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2017-01-20 04:50 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (173 votes). Check out past polls.