Re: [VOTE] Expectations
| From: | Crypto Compress | Date: | Sat, 28 Feb 2015 19:36:54 +0000 |
| Subject: | Re: [VOTE] Expectations | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84084@lists.php.net to get a copy of this message | ||
Am 28.02.2015 um 20:08 schrieb Patrick Schaaf:
Am 28.02.2015 19:32 schrieb "Crypto Compress" <cryptocompress@googlemail.com <mailto:cryptocompress@googlemail.com>>:
class BankAccount {
function Add($amount) {
assert($amount > 0);
// ... code block ...
}
}
Now the programmer implementing "code block" to gracefully handle $amount > 0 has a problem. There is no way to (Unit)test failing path on development machine. Code after assertion is never called for failing contitions. What to do?
Put the assert AFTER handling the always-to-be-done validation, of course. Doesn't make sense otherwise.
Patrick
if ($amount > 0) { ...code block... }
// else {
throw new WrongAmountEx();
// }
Frankly i can't see any point in using assertion after checked expression thus duplicate the expression. It's simple a bug. As situation is clearly wrong, throw/exit/die and change code flow as desired. This is not the "conditionally unreachable code" case i argue about.