in reply to When to use modules?

Modules and why one must use them. Hrmmm ...

The reason you should use a module is because someone else much smarter than you has figured out the stupid details so that you don't have to learn it, understand it, and remember it. More importantly, when the stupid details change (as they always will), you don't have to even be aware that they changed. The module will DWIM and life will be good.

Let's take your example. Others have already mentioned dealing with timezones and other headers being outputted. I'm going to go further and say "What if you're potentially not always dealing with HTML?" Sounds stupid? Maybe not ...

I'm starting to design a Data-Access Layer (DAL) for interfacing two completely disparate applications (one in Perl, the other in Java) onto the same database. For ease of development, I'm going to use Apache as the server and use XML as the messaging structure. It will be very HTTP-like in that the client will send a request and the server will send a response. I can see using the concept of cookies to aid usage of the DAL from both the Perl and the Java sides. Maybe, a CGI-like module is written to use the same interface?

Ok, maybe that wasn't as believable. But, how about this one? I just wrote a generalized datastream handler. It doesn't make any assumptions about the type of the file, if you give it a filehandle. This allows me to use IO::File, IO::Zlib, and any other IO::* module, plus typeglobs and stuff returned by open().

Modules provide interfaces. If two modules conform to the same interface, they can be treated the same way. This is why IO::All is so powerful (and is even possible!)

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: When to use modules?
by flyingmoose (Priest) on Mar 22, 2004 at 14:22 UTC
    The reason you should use a module is because someone else much smarter than you has figured out the stupid details...
    Not always smarter -- just less lazy :)

    In other words -- the wheel has already been invented, and the wheel is found to be good. But wheels are simple, and you could probably build a wheel, but you are building a car instead. You should never reuse square wheels, of course. But the part about not having to deal with 'stupid details' is absolutely right. It's all about not having to worry about stuff that you know you could re-implement (like wheels or spark plugs -- Lambourghini doesn't make spark plugs, do they?).

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. I like those best. Ah, what a good job...

      I would like to note that although new modules are sometimes (ok very often) buggy, They are put to heavy use by the community. This use tends to find and fix those bugs fairly quickly. (This is one of the benefits of Open Source Software as mentioned in The Cathedral and the Bazaar.)