[Melbourne-pm] Namespace Guidelines?

wigs at stirfried.org wigs at stirfried.org
Tue Jan 1 14:35:25 PST 2008

On Tue, Jan 01, 2008 at 10:32:25PM +1100, Paul Fenwick wrote:
> As for OO guidelines, it's fairly natural for one to expect containership to
> mean inheritance.  For example, Bird is a parent of Bird::Chicken is a
> parent of Bird::Chicken::Australorp.

I disagree with this - in the general case I have not found this expectation to
be natural at all.  The principle problem I have with containership implying
inheritance is that it violates DRY.  You have duplicated information in both
the @ISA/use base statements, as well as in the module name, and thus adds more
to the maintenance costs of your code.

Consider this situation: what happens if you ever need to refactor one of your
super classes?

Say, for example, you decide one day that, besides dealing with Birds, your code
also needs to deal with Reptiles, which at some abstractly primitive level bears
some similarity to birds.  So, inspecting your code you find some reusable
elements within Bird.pm, and you pull that up into Animal.pm; so that Reptile.pm
(and thus Reptile::Lizard and Reptile::Snake) can inherit it.

At this stage you either have a dilemma with your code:
  - do you break your module naming convention, and have

      Bird::Chicken isa Bird isa Animal,
      Reptile::Snake isa Reptile isa Animal?

  - or do you try to stay consistent with the naming scheme and rename
    *everywhere* the classes involved?

      Animal::Bird::Chicken isa Animal::Bird isa Animal
      Animal::Reptile::Snake isa Animal::Reptile isa Animal?

    (And then what happens when you want to start involving Plants in your
    object taxonomy?)

Secondarily, Perl permits multiple inheritance.  How would this be best included
into any module name that implied inheritance via containership?

> Apologies for the not particularly in-depth response, however if you do find
> a good set of guidelines written down, I'd love to see them.

Agreed, I would also like to see them too.  I do remember mention about the
'Local::' namespace, but could not find any suitable documentation in a timely
manner for an earlier reply to this thread.

Happy New Year.


More information about the Melbourne-pm mailing list