Is using ELSE bad programming?

Posted by dave.b on Programmers See other posts from Programmers or by dave.b
Published on 2010-12-20T11:11:24Z Indexed on 2011/01/06 21:59 UTC
Read the original article Hit count: 294

I've often come across bugs that have been caused by using the ELSE construct. A prime example is something along the lines of:

If (passwordCheck() == false){
    displayMessage();
}else{
    letThemIn();
}

To me this screams security problem. I know that passwordCheck is likely to be a boolean, but I wouldn't place my applications security on it. What would happen if its a string, int etc?

I usually try to avoid using ELSE, and instead opt for two completely separate IF statements to test for what I expect. Anything else then either gets ignored OR is specifically handled.

Surely this is a better way to prevent bugs / security issues entering your app.

How do you guys do it?

© Programmers or respective owner

Related posts about self-improvement

Related posts about programming-practices