Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Ingy's "Swiss Army Light Sabre" - or, "how do you design your APIs?"

by mvc (Scribe)
on Mar 27, 2004 at 16:07 UTC ( #340268=note: print w/ replies, xml ) Need Help??


in reply to Re: Ingy's "Swiss Army Light Sabre" - or, "how do you design your APIs?"
in thread Ingy's "Swiss Army Light Sabre" - or, "how do you design your APIs?"

My main objection:

my $foo = io('some/thing');

Yes it would be better to trap such a mistake ASAP. Would this be OK?

my $foo = io(-filename => 'some/thing');

You could even add some kind of policy enforcement aspect that will trap all dubious instantiations on runtime.

I am not worried about a developer calling $foo->slurp when the intention was to use $foo as a directory, for the same reason that I am not worried about it being used as a Person object. It is just a coincidence that file and directory features are in the same physical package.

BTW: The Java class java.io.File is also a file or a directory, and it implements some methods that are directory specific, like listFiles(). So it is a similar situation, despite the static typing. Of course that is a poor example, and anybody with a brain would use a util lib, e.g. the apache commons.

It is leaky abstraction, but it looks like a pretty cool one to me! The freedom from having to check return values is a justification for this by itself.


Comment on Re: Re: Ingy's "Swiss Army Light Sabre" - or, "how do you design your APIs?"
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2015-08-01 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls