|Perl Monk, Perl Meditation|
Module naming problems, or time ill spent.by Dog and Pony (Priest)
|on Jun 12, 2002 at 22:32 UTC||Need Help??|
Once upon a time...
... I was working with java. Now I (mainly) don't, and I do not really miss it much. I liked java, and I still do, but as long as I have for instance perl instead, I'm fine. I still have some tasks do to that require poking in java systems, so I keep my java knowledge up to date, or at least, I don't let them stagnate too hard.
In java, everything is an object, and thus, everything you write is classes. They may still be purely functional classes, containing only static methods that don't use any object behaviour, but you still put everything in a class. The difference (in perl terms) is when you do Module::function(), that is what we called a static method, and when you have an object that you do $object->method(), that is a ``real'' method.
Below here, I will take some small liberties with the definitions of modules, classes and suchlike. When I write modules, they are most oftenly classes too, even though I do know that a module need not have any class in it at all. Depending on your view, this may be viewed as semantics - to java, it would still be classes, in perl they are not. Just so you follow me along later here.
In effect, it would quite be as if everything you wrote was put into .pm files, or modules. Like in perl, you can put several classes (packages) in one module, but you can't, in java, have any .pl files. This is not really a problem, since all you have to do to get your ``.pl'' file is create a class (or ``module'') with a main method in it, much like in C, and you take it from there. It does take a little more effort though, as you must declare the class and all that, but with some templates or macros, you're fine.
Get to the point, already!
Anyhow, in java, since you do small things there too, you create a couple of classes when you write a program. You create Foo.java, Bar.java, and Baz.java, define main in Foo, and off you go. For bigger projects, you can qualify your classes via longer search paths - it is called packages. So the real name of the classes is perhaps wolf.ant.Foo, wolf.ant.Bar etc. A recommended practice is to put your company's domain backwards there, as in org.perlmonks.Foo.
What I am slowly getting at is that, in java, I used to create the classes Foo, Bar and Baz, and didn't really qualify them more than that. Not so in perl.
I think I've gotten a bad case of the CPAN's, in this case, when I do write a module, or a set of modules, I try to figure out where it would fit if there is a fitting category, or at least name it in with a top- and subname. Examples would be, if I wanted to write some text munging module, a fitting name might be Text::Munge, perhaps?
Yes? That is good, isn't it?
Well, yes. At least if the module, unlikely as it is, would ever turn up on CPAN. The problem at hand, is that I seem to spend waaay too much time on aptly naming my modules than it is worth, especially before I have any idea if it would end up on CPAN. I have yet to produce anything worthy of going there, which may be a hint.
Still, I somehow feel that I must name it in a good way. This can cause problems. I am recently toying around a little with a small set of modules that I thought would handle a little testing, write other module stubs and a little such from certain data. Nothing really serious, but it really struck me how much time I spent on figuring out a good name for the whole bundle.
For those that wonder, yes, I am aware of ExtUtils::ModuleMaker, and all the Test:: modules, it is in no way a replacement, just something that I figured will save me some extra time, and allow me to be lazy. If I get around to getting something that actually does any of that together, you will be the first to know.
As you may start to suspect. so far I have wasted time instead of saving it.
The problems I have
Being quite OO-oriented, for good and for bad, I usually write my stuff with objects and classes. Perl has taken some of that out of me, when it is really not necessary, but I still like the OO way of doing things. So I have a set of classes, each in their own module for clarity, and then it started.
I could name my module set Test::X[::X], which is quite fitting for where I started - I wanted to help out my test writing. Then I realized that I could also do Module stubs (trying to write the tests first, why not provide fitting stubs too, probably with ExtUtils::ModuleMaker?). The namespace Test::X suddenly didn't fit anymore.
Well, how about Module::X then? That is a little bit better, I could go Module::Test::X, and Module::Create::X, perhaps. There is still more. Without bothering with any more detail, let's just say that I really am touching at least three different top categories here, if I should name everything ``right''.
Since my ideas, the possibilities, and all such grows and shrinks as I try this or that, or think things through, this process can go on and on forever. Just because I want it to fit in. And if you wonder why I just don't rip it apart (I still might), that was because it everything produced comes from a common source. Which might give an apt name in itself, but then, you could also just use this one...
Of course I worry too much. I just realized the full impact of it. :)
The solution, as I see it
Well, upon realizing this, I also understood that I shouldn't have forgotten my old, java style of doing things so easily.
I should not really give a d*mn about what ``category'' it should be put in, unless it is blatantly obvious from the start. I should just create the modules, or classes, I see fit, give them a name like Test, Write, etc, or whatever I feel is correctly describing it inside my bundle. Then, after creating new modules, removing them, merged them and split them as happens during refactoring and as the work progresses, when it all works it should come down to two alternatives:
How about you?
I didn't only post this to whine about my problems. Partly, I also wanted others, if there are any, with the same problem to at least stop and think for a while, they too.
But most importantly, I wanted to ask a few questions:
Also note that while I am not writing modules to end up on CPAN or anything like that, I still would like my modules to follow the current standard, and if anything I ever produce would be of use to any other, I want to make sure they can use it. Also, even when using your own private module at home, it is nice if it kind of fits in the rest of the pattern.
Thank you for your time. :)
You have moved into a dark place.
It is pitch black. You are likely to be eaten by a pantomime goose.