SimonSaysCake:

It's one of the advantages of perl, IMO. One of the problems with object-oriented programming, as I see it, is that there's an internal pressure to make your classes "complete" so that users can do all the tasks they would reasonably expect to be able to do with the class. Many languages require that a class be created in a single source file, so frequently you'll get occasionally useful functionality thrown into the file, when most applications don't actually need it. As the class ages, more and more stuff gets put in there.

The ability to add some functionality to a class without inheriting from it is pretty nice, as you can simply include other modules at the top of your program. So if you need some rarely-needed functionality, you don't need to subclass something to add the functionality and then update your script to use the new subclass. Using your extra functions with another package of extra functions is similarly easy, just add the functions into your class and you're done. No need to refactor your application, no need to worry about how to refactor the extra functions into yet another class hierarchy to let them coexist.

If it's truly a one-off function, you can just add it into your script, and it'll still act as if it were part of the package proper.

It's not something you'll need to do all the time, but it's flexible and clean, compared to having to worry about inheritance headaches.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Packages with subs using fully qualified class names, not always their own. by roboticus
in thread Packages with subs using fully qualified class names, not always their own. by SimonSaysCake

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.