Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Abstract Packages

by hv (Prior)
on Aug 04, 2004 at 14:19 UTC ( [id://380004]=note: print w/replies, xml ) Need Help??


in reply to Abstract Packages

Any particular reason you disallow both "Processor" and "Processor\n" as package names? I'd have been inclined to use an nice simple string compare instead of a regexp:

... if $class eq 'Processor';

For more generality, I'd take advantage of the builtin symbol to make the same check work everywhere:

... if $class eq __PACKAGE__;

(And, for the record, I have no problem with ref($this) || $this.)

Hugo

Replies are listed 'Best First'.
Re^2: Abstract Packages
by Ovid (Cardinal) on Aug 04, 2004 at 16:55 UTC

    I've no problem with ref $this || $this either, but there is absolutely no consensus in the Perl community regarding expected behavior when a constructor is called on an instance. (Maybe nethack should get launched.) That's the real problem with that construct. If the programmer puts it in the code, he or she should understand why it's being put in and document it. Otherwise, why bother writing it?

    Update: Now that I think about it, using this without documentation is even more problematic with an abstract base class. If I'm subclassing a module, I'm tightly coupling my subclasses behavior with that of my superclass(es). It's even more important that I understand the behavior of those classes with such coupling, therefore I would be even more inclined to ding someone for ref $proto || $proto unless that person had clear documentation. If it's not documented, it's not a contract with those who use the class and, as such, cannot be defined behavior. Using undefined behavior is a Bad Thing and subclasses should be especially vigilant not to do this (not that I would excuse this in everyday code, either.)

    Cheers,
    Ovid

    New address of my CGI Course.

Re^2: Abstract Packages
by Velaki (Chaplain) on Aug 05, 2004 at 11:43 UTC

    When I was using __PACKAGE__ it was evaluating to something other than 'Processor', and thus would still allow instantiation of the abstract base class.

    -v
    "Perl. There is no substitute."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found