Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Hiding the Module 'Path'

by dvergin (Monsignor)
on Jan 26, 2002 at 08:03 UTC ( #141723=perlquestion: print w/replies, xml ) Need Help??

dvergin has asked for the wisdom of the Perl Monks concerning the following question:

Here's one that caused me to sit back and go, "Hmmmm...".

Reading through some well-distributed code I found this near the top of the main script:

use lib qw(./include); use Cwd; # avoid needing to refer to SnortSnarf packages as SnortSnarf::*, even + if # that is where they really are: sub BEGIN { push(@INC,map("$_/SnortSnarf",grep(-d "$_/SnortSnarf",@INC +))); } use SnortFileInput; use HTMLMemStorage; use HTMLAnomMemStorage; use SnortRules; etc. etc.
Now, although I have never seen the little meme in that BEGIN block before, I understand what it is doing. (That's not the question.) My question is this: "is this a Good Practice?" What is the point?

So far as I can see, this bit of source-hiding simply saves a few keystrokes near the top of the file. And if done to access it could lead to some maintainance annoyances. Imagine adding several module paths to @INC and then trying to find the modules later: "Let's see, I wonder if the module referred to in 'use Parser' is XML::Parser or HTML::Parser..."

It's cute. It's slick. But is it Good?


Update: Thanks to the responders below for confirming my misgivings. I'm open to learn new approaches, but this one felt wrong from the get-go.

Replies are listed 'Best First'.
Re: Hiding the Module 'Path'
by wog (Curate) on Jan 26, 2002 at 08:12 UTC
    I would say this is not good. Not only is there the namespace conflicts issue you mentioned, but there is also an issue of how use works. use MODULE; is equivilent to BEGIN { require MODULE; MODULE->import(); }. This shortcut makes it so use will not be able to run the import method on the module in question, which can greatly affect how a module works. (I am, of course, assuming that these modules being "short-cutted" are really define packages whose name begins with SnortSnarf:: or whatever.)
Re: Hiding the Module 'Path'
by n3dst4 (Scribe) on Jan 26, 2002 at 17:00 UTC
    Surely it's more arse-ache to write that BEGIN block than to add SnortSnarf:: to the use's?

    It certainly is cute and slick, though. In that respect, it's much like a baby seal covered in crude oil.

(jptxs)Re: Hiding the Module 'Path'
by jptxs (Curate) on Jan 26, 2002 at 22:31 UTC
    strikes me that this isn't even cute and slick. what is the reason for hiding this? I have to assume someone using this would be aware of the requirement for these modules, or, at least, that there is a directory structure that this tar file they've unpacked has created. If they have been curious and competent enough to take on reading or modifing the source, why would we assume the need to hide these paths from them? Sure it's a nice trick, but a nice trick for no reason can't be a good idea...

    We speak the way we breathe. --Fugazi

Re: Hiding the Module 'Path'
by Aristotle (Chancellor) on Jan 27, 2002 at 01:04 UTC

    I have to agree with wog and jptxs. I'm speculating that whoever did this was not aware of any but the most obvious implications. That's hair-raisingly false laziness. Conventions form over time for good reason. Challenging them may lead to better solutions, but one shouldn't do so mindlessly. I often find myself enlightened and sticking to a convention after questioning it even if I thought it really stupid before.

    Finally, I think the fact that everyone here disagrees with that code and even you yourself have doubts is a pretty clear indication of its worth.

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://141723]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2021-03-06 08:45 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (116 votes). Check out past polls.