title: defensive coding practices
body: <p>Ever since I first wrote</p>
  
  <pre><code>if ($a = 5) {
     #  do something with $a, e.g.
     print "$a";
  }
  </code></pre>
  
  <p>and went through the normal puzzling session of </p>
  
  <ul>
  <li>why is the result always true</li>
  <li>why is $a always 5</li>
  </ul>
  
  <p>until I realized, I'd assigned 5 to $a, instead of performing a comparison.</p>
  
  <p>So I decided to write that kind of condition above as </p>
  
  <pre><code> if (5 == $a)
  </code></pre>
  
  <p>in other words: </p>
  
  <p><strong>always place the constant value to the left side of the comparison operator, resulting in a compilation error, should you forget to add the second "=" sign.</strong></p>
  
  <p>I tend to call this <strong>defensive coding</strong> and tend to believe it's <strong>a cousin to defensive-programming</strong>, not on the algorithmic scale, but keyword by keyword. </p>
  
  <p>What defensive coding practices have you developed? </p>
  
  <hr>
  
  <p><strong>One Week Later:</strong> </p>
  
  <p>A big "thank you" to all who answered or might add another answer in the future. </p>
  
  <p>Unfortunately (or rather fortunately!) there is no single correct answer. For that my question was to broad, asking more for opinions or learnings of experience, rather than facts. </p>