|
home—lects—hws
D2L—breeze (snow day)
For this homework, you'll submit three files, both on D2L and as hardcopy:
As in
lecture
and its example “some-web-page.php”,
silly-page.php should start with “
Notes:
You do not need to check for invalid-inputs to your functions. E.g.: if I ask for a function taking in (say) a number and a string, and you repeat in your function-comment that your function handles a number and a string, then you don't need to check for being given incorrect inputs — that's the caller's problem, not yours. Similarly for more refined types like "non-empty-string" or "integer in the range [1,12]": if it's in the comments as a pre-condition, that'll suffice.
(We'll talk about validating input received from the (external, untrusted) user later.)
1
You may have seen in Web I that text not enclosed
in
2 While the defensive-programming can be helpful in bigger projects (esp. in untyped languages like php), it's never interesting code. If you DO want to do the checks anyway, that's fine, but do all the type-validation right away (before you enter the 'real' function-logic), and throw an error if something goes wrong (don't continue and return some sort of odd, undocumented answer). For example:
function foo( $someNum ) { // error-check NOT required for this class, but if you want to: if !(is_numeric($someNum)) { throw new InvalidArgumentException( 'foo: expected number, given ' . $someNum ); } // ...now put your real code, uncluttered by further type-checks. } |
home—lects—hws
D2L—breeze (snow day)
©2016, Ian Barland, Radford University Last modified 2016.Sep.05 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |