2008/6/28 Andrew Ballard <[EMAIL PROTECTED]>: > Say anything about efficiency never did I. :-) I was merely commenting > on a personal preference based largely on my perspective as a native > speaker of (US) English. Now - if I WERE to address efficiency, I > don't find "Yoda speak" to be any more efficient. It's usually the > same words just in a different order. What's more that order, while > quite natural for some languages, is not natural to me at all. As Bob > mentioned, it requires a little extra thought for my brain to push > certain phrases onto the mental stack before I can pop them off in an > order that "makes sense." In programming terms, any code that requires > the same amount of statements but requires more cycles to process is > not what I would consider more efficient. > > As far as the programming practice that Colin was advocating, it is > not a bad habit. And as far as the computer is concerned, the > efficiency is a wash since the number of internal steps probably > doesn't change much. However, it doesn't always work. (I know - no one > claimed it did.) > > <?php > if ($challenge_password_hash = $stored_password_hash) { > echo 'Welcome to the club!'; > } else { > echo 'Stay out! This club is for members only!'; > } > ?> > > Andrew >
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 ?> 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?