title: Do ternary operators tend to bug / defect injection?
body: <p>A discussion has come up in my office about the use of ternary operators. There are two sides to this discussion.</p>
  
  <p>Side 1) That ternary operators are easy to write and read, therefore convenience is a net cost-savings.</p>
  
  <p>Side 2) That ternary operators are difficult to maintain because they require excess code-churn should they ever need to be modified to be even the slightest bit more complex.</p>
  
  <p>Extra nerd points if you can cite any actual studies done by a top-tier institution on this subject... I'm very interested to see hard data on this.</p>
  
  <hr>
  
  <p>My theory is that the best code is code that can change and adapt easily, and that the less complexity that change requires, the less chance there is for a break. Example:</p>
  
  <pre><code>$id = $user-&gt;isRegistered() ? $user-&gt;id : null;
  </code></pre>
  
  <p>Ok, so this is completely valid, but what happens when the code needs to change to become something slightly more complex?</p>
  
  <pre><code>$id = null;
  if ($user-&gt;isRegistered() || $user-&gt;hasEmail()) {
      $id = $user-&gt;id;
  }
  </code></pre>
  
  <p>Any sane programmer would look at the ternary and convert to standard if/else. However, this required a 4-line change versus starting with:</p>
  
  <pre><code>if ($user-&gt;isRegistered()) {
      $id = $user-&gt;id;
  }
  </code></pre>
  
  <p>Which would only require a 1-line change.</p>