[UPHPU] Coding Correctness

Orson Jones orson.uphpu at afriskito.net
Thu Oct 9 15:21:44 MDT 2008


Hmmm, apparently, the list dismisses email that is sent from a smtp server other than the one for
which the email address would apparently belong to.

Onward (finally)

Jennifer Charrey wrote:
> c) The second function does extra work by doing up to two extra mods
> when the number is not even. If it's an integer and it's not even, it's
> odd. No need to do two more operations, allow more pathways for bugs
> (what if you'd forgotten about the -1 case?), make the code less
> readable, etc.

Ohhh, extra work!
They missed the extra else, don't forget to cover this case.
Also, added commas for clarity in output.

function evenOrOdd ($number) {
  if (is_numeric($number)) {
    if (($number % 2) == 0) {
      echo 'Your number, ' . $number . ', is even.';
    } else if (($number % 2) == 1 || ($number % 2) == -1) {
      echo 'Your number, ' . $number . ', is odd.';
    } else { // change to exception??
      echo 'Your number, ' . $number . ', is fractional.';
    }
  } else { // change to exception??
    echo 'Your input, "' . $number . '", is not a number.';
  }
}

Orson

PS. Perhaps we should change the errors to throw exceptions instead of printing random stuff out.



More information about the UPHPU mailing list