Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: "But I'm never going to..."

by Jenda (Abbot)
on Apr 08, 2004 at 23:24 UTC ( [id://343800]=note: print w/replies, xml ) Need Help??


in reply to "But I'm never going to..."

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

Replies are listed 'Best First'.
Re: Re: "But I'm never going to..."
by QwertyD (Pilgrim) on Apr 16, 2004 at 00:15 UTC
    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?

    That's why Ken Williams, who maintains File::Spec, wrote Path::Class. It's a really, really nice object oriented module for path manipulations. Check out the Synopsis section of its POD to see how much better it is.


    Once it's Turing complete, everything else is just syntactic sugar.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://343800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-16 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found