Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Pre and Post Conditionby CheeseLord (Deacon) |
on Aug 23, 2001 at 01:05 UTC ( [id://107144]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Meditations
|
|