2008/6/29 Colin Guthrie <[EMAIL PROTECTED]>: >> In these instances you could rely on != behaviour instead of == >> behaviour, like this: >> >> <?php >> if ($challenge_password_hash != $stored_password_hash) { >> echo 'Stay out! This club is for members only!'; >> } else { >> echo 'Welcome to the club!'; >> } >> ?> >> >> or, better yet: >> >> <?php >> if ($challenge_password_hash != $stored_password_hash) { >> echo 'Stay out! This club is for members only!'; >> exit; >> } >> echo 'Welcome to the club!'; >> // Lots of code here that just saved itself another indent in my IDE >> ?> > > Indeed. The technique obviously only works for constants, and it wont help > with variable -> variable comparisons (unless you do something really stupid > like put the first expression in quotes!). > > Using != when possible is a good idea but I guess you have to draw the line > as to moving your preferred "flow" of logic around to fit in with a > technique for reducing the possibility of logical errors. > > Even your example above hints at another "political" minefield - Early > Return or Multiple Return Points.... (s/Return/Exit/ in this case) Let's not > even go there!!! >
Why not? I do this often, but I am not a professional programmer. I find this to be very useful. Dotan Cohen http://what-is-what.com http://gibberish.co.il א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?