Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Pre and Post Condition

by CheeseLord (Deacon)
on Aug 23, 2001 at 01:05 UTC ( [id://107144]=note: print w/replies, xml ) Need Help??


in reply to Pre and Post Condition

Not only do I rarely engage in pre-condition checking, I would discourage it. I'm sure people will disagree with me on this, but it seems to go against the way I want my code to go: the sub does what it says it does, and nothing more. I include documentation of the pre-conditions so that people calling my sub will know what they can send in - but I'm not about to tell them that they can't break the rules - I'm only stating that these are the only conditions which I'm sure my code operates correctly under (and even then I'm wrong sometimes).

I think it's analogous to a warranty - you see the terms of the warranty (the pre-condition), and it's up to you to handle the item correctly (passing correctly formatted / sequenced variables). If you choose not to, well, you might get what you want, or you might not. But you broke the rules, so I'm not gonna guarantee you anything in this case.

Don't let my ranting discourage you, though - do what you feel comfortable with. Certainly, checking that data is correct makes things nice for the user, but at the same time, you restrict the user's freedom. There's no real clear direction as to which is better - it's all about finding a good balance to that, I guess...

Update: I should point out that I am in no way saying that checking input is a bad idea - I mean, if perl didn't choke on syntax errors, you'd never have seen me here on PM. I just felt the need to bring up the point that adding in tons of input checks can result in your code becoming far too complicated, and can cause you to lose sight of your objective.

His Royal Cheeziness

Replies are listed 'Best First'.
Re: Re: Pre and Post Condition
by E-Bitch (Pilgrim) on Aug 23, 2001 at 02:39 UTC
    I see your point. I would say this, however... In order to make an application robust, I would say use the condition checking, and when making a utility (like a module), let it be flexible....

    _________________________________________
    E-Bitch
    Tempora Mutantur Nos et Mutamur in Illis
    "The Times are Changed Even as We are Changed in Them"
Re: Re: Pre and Post Condition
by John M. Dlugosz (Monsignor) on Aug 23, 2001 at 02:56 UTC
    I call that a precondition regardless of whether the code checks it or not. Your docs list what the function assumes, rather than letting the user guess or incorrectly mix up implementation details with specifications.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-19 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found