On Thu, Oct 9, 2008 at 2:23 PM, Ash <[EMAIL PROTECTED]> wrote:
> That error message is kinda wtf'y.
I am of the opinion that an error message is entirely superfluous.
The function is named evenOrOdd, which obviously applies only to
numbers. Its first and only argument is called $number, which is
obviously intended to be a number. So you've got obviousness on the
calling side (when you write code calling evenOrOdd) and obviousness
times two when you're looking at the code for evenOrOdd. (For the
terminally stupid, he even wanted to include a link to Wikipedia in
the comments so we could find out what exactly it means to be even or
odd - as if anyone who's going to be reading our code doesn't already
know.)
If you absolutely must make your code idiotproof (which of course just
means you're being careful because everyone, including the august and
sage author of this email, does idiotic things several times a day)
then use exceptions, as Kirk Cerny suggested. Then whoever's using
your function can wrap it in a "try" if they need to be careful, or
they can just throw crap at it if they don't care how horribly things
go wrong when something gets fubared.
Here's my entry, pursuant to my previously posted quote:
function eOO ($n) {
if (is_numeric($number)) {
echo (($n % 2) == 0) ? "even" : "odd";
} else {
throw new Exception('not a number');
}
}
I'll spare you all the pain of showing how it could be done even
better in Lisp ;-)
Dan
_______________________________________________
UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net