Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I think one of the reasons File::Spec is not used more is that the default interface is ... erm ...strange. File::Spec->catfile(...)? Beg your pardon?

Yeah OK so it uses inheritance to allow the default implementations of the functions to be overriden ... but that's just an implementation detail. And implementation details should not leak into the interface.

The interface provided by File::Spec::Functions is the one that should have been the default one. It looks like the interface of most Perl modules, it allows you to import (or not) functions into your namespace just like any other well behaved module.

A module that's OO and provides only static methods has no reason to be OO at all. This aint Java.

Actually it seems to me OO inheritance is not the best implementation. It's slow. There is no reason why the right versions of the functions could not be found just once, on startup. I think it would be better to do something like this:

#SpecBase.pm package SpecBase; require Exporter; @ISA = qw(Exporter); @EXPORT = @EXPORT_OK = qw(foo bar); sub foo { print "The base foo()\n"; } sub bar { print "The base bar()\n"; } 1; #SpecChild package SpecChild; require Exporter; @ISA = qw(Exporter); @EXPORT = @EXPORT_OK = qw(foo bar); use SpecBase qw(foo); # the inherited functions, to prevent the "Subro +utine bar redefined" warnings sub bar { print "Overwritten bar()\n"; } 1; #Spec.pm package Spec; ... sub import { shift(); ... find out the right version require $the_right_version; $the_right_version->import(@_) } 1;

Update: Actually looking into the code in File::Spec::Functions I see that the inheritance tree is not being searched through each time. The right method is found by the ->can(). But I think the closure also is not free.

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature


In reply to Re: "But I'm never going to..." by Jenda
in thread "But I'm never going to..." by water

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found