title: Why do some experienced programmers write comparisons with the value before the variable?
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/148298/how-to-check-for-equals-0-i-or-i-0">How to check for equals? (0 == i) or (i == 0)</a><br>
    <a href="https://stackoverflow.com/questions/271561/why-does-one-often-see-null-variable-instead-of-variable-null-in-c">Why does one often see &ldquo;null != variable&rdquo; instead of &ldquo;variable != null&rdquo; in C#?</a>  </p>
  </blockquote>
  
  
  
  <p>I've been having a look at an odd tutorial here and there as well as some DirectX code and noticed that many experienced C++ programmers write expressions in the following way:</p>
  
  <pre><code>(&lt;constant&gt; == &lt;variable&gt;)
  </code></pre>
  
  <p>rather than what my conventional wisdom seems to prefer:</p>
  
  <pre><code>(&lt;variable&gt; == &lt;constant&gt;)
  </code></pre>
  
  <p>E.g. <code>if (NULL == ptr)</code> rather than <code>if (ptr == NULL)</code>. I prefer the second alternative, if there are no other reasons for choosing the former, my reason being that the variable seems to be the "receiving" end of the expression. </p>
  
  <p>But I suspect the former is used to avoid inadvertently assigning the value of the constant to the variable by using <code>=</code> rather than <code>==</code>. Would that be correct?</p>