process - What do you think when a Boolean "if" has three resulting code paths? -
(background: previous job, co-worker , end discussing bug pile during lunch. began develop topic called "bug of week". doubt have material 52 posts year, here's first one...)
reported by:
qa tester reading html/js code write functional test of web form, , saw:
if (form_field == empty) { ...do stuff empty field } else if (form_field != empty) { ...do stuff non-empty field } else { ...do stuff never done }
after couple embarassing attempts, tester realized couldn't trigger alert strings hidden in third block.
things i'm wondering are:
- is problem more or less language specific (can non-js people learn lessons here?)
- are there legitimate reasons code ended way?
- what approaches should used find/address problem (code coverage, code review, blackbox testing, etc.)
a couple other points:
i'm hoping can keep positive. imagine person work (in company not encourage flaming). whatever mean things might think of guilty party, thought them too.
i'm not coder profession. checked wiki box, in case wants provide more literal example, or add base of thread.
[edit] similar https://stackoverflow.com/questions/114342/what-are-code-smells-what-is-the-best-way-to-correct-them
is problem more or less language specific (can non-js people learn lessons here?)
this language-agnostic problem. it's quite easy write following in java, example:
if(x) { //do } else if(!x) { //do else } else { //never, ever, }
the key thing remember "if(!x)" not required. making simple "else" create simpler code.
are there legitimate reasons code ended way?
sort of. it's standard practice else condition exist when fall-through needed. problem programmer wasn't thinking single "(form_field != empty)" same simple "else". point out him , should kick himself. if doesn't, question role on team.
what approaches should used find/address problem (code coverage, code review, blackbox testing, etc.)
static code analysis tools can catch sort of issue. however, i'm not aware of javascript. jslint can catch lot of bad stuff, not logic flow issues.
Comments
Post a Comment