Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: OO style question: how much information to hide?

by PodMaster (Abbot)
on Jun 11, 2003 at 00:50 UTC ( #264923=note: print w/ replies, xml ) Need Help??


in reply to OO style question: how much information to hide?

Come now Ovid, you're over thinking it. All tokens must not have attr methods, cause all tokens do not have attributes. Divide and conquer. I say you just go with Re: Re: XML::TokeParser::Simple - pretty much like HTML::TokeParser::Simple like you said you would. Your start tags can have those attr methods, but your text/comment/end tokens surely must not.

Perl should definetly die with Can't locate object method "del_attr" via package ... if you try that on a text token.


MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
** The Third rule of perl club is a statement of fact: pod is sexy.


Comment on Re: OO style question: how much information to hide?
Re: Re: OO style question: how much information to hide?
by sauoq (Abbot) on Jun 11, 2003 at 02:59 UTC
    Perl should definetly die with Can't locate object method "del_attr" via package ...

    I'm fine with dying if throwing exceptions is the documented error handling methodology and is used consistently.

    Sort of¹. . .

    As far as the "definetly" [sic] part of that statement... well, why?

    Gracefully handling the error isn't such a bad thing is it? Why throw an exception and force² your user to handle it when you could move on silently and leave no harm done?

    I do think that the module's clients should have access to the error if desired. For example, an object can set an error condition and make details accessible via an error() method. Providing that, along with the is_start_tag() method, could give Ovid's module's clients the ability to ask "should I do this?" as well as "did I do what I expected?" And, really, that should be enough.

    I understand that from an OO purist perspective, what I'm suggesting is blasphemous. It's lackadaisical, slackish, and lacking the rigor that OO is supposed to enforce. But hey, if you really wanted that, you could shackle yourself to Java or C++ or what-have-you.

    I don't want to give the wrong impression. I'm all for rigor, particularly in large projects. But, for a general module which is likely to be used in far more small projects than large ones, I'm not convinced enforcing rigor is the right way to go.

    1. I really hate using eval and checking $@. I think it's ugly. But that's a personal issue.

    2. And this is the real reason I hate using die() for error handling. It requires that the module's clients use eval, even in cases where it doesn't matter. If you provide another way of handling those cases, then you are in the precarious position of maintaining two separate error handling methodologies, so it isn't a realistic option.

    -sauoq
    "My two cents aren't worth a dime.";
    
      ... I really hate using eval and checking $@. I think it's ugly. But that's a personal issue.
      The user doesn't have to deal with it -- that's why you have the is_ methods, so the user doesn't try foolish things. I'm not an OO purist or whatever, I just dislike daft interfaces.


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
      ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Re: OO style question: how much information to hide?
by mvc (Scribe) on Jun 13, 2003 at 20:46 UTC

    So start tags and end tags are different things. Then why is there a $token that can be either? You should not get to that stage. From where do you get the tokens? Can you ask for start tags only? If so, you do not have to choose between keeping the condition, or silently doing a no-op.

    If you must visit hierarchies of objects of different types, use Visitor.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-12-20 12:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls