Applying the Linus Torvalds “Good Taste” Coding Requirement
I dunno, the first example seems unsatisfying. The original has that ugly condition, the &quot;good&quot; version seems overly clever. And for all the talk of taste and aesthetics, both versions ignore an elephant in the room: defensively dealing with `entry` being absent from the list.<p>Not that I&#x27;ve never abused addresses like this. But having written this multiple times, I currently prefer something like this:<p><pre><code>  remove_list_entry(entry)
  {
      if (head == entry) {
          head = head-&gt;next;
          return;
      }

      for (prev = head;  prev-&gt;next;  prev = prev-&gt;next) {
          if (prev-&gt;next == entry) {
              prev-&gt;next = prev-&gt;next-&gt;next;
              return;
          }
      }
  }
</code></pre>
There&#x27;s still an `if`, but it isn&#x27;t so bad since it&#x27;s an early exit. What is &quot;tasteful&quot; about hiding the fact that one of the cases is <i>far</i> simpler than the other? There&#x27;s conditionals and then there&#x27;s conditionals. There&#x27;s cases and then there&#x27;s cases.<p>The other benefit of this approach: you eliminate segfaults by construction, because the `while` has been replaced with a much more <i>normal</i> `for` loop iterating through the list. Keeping it normal is 80% of the secret to avoiding security holes.<p>Rather than appealing to something nebulous like &quot;taste&quot;, I prefer to focus on concrete functional benefits. What is a situation where someone using or modifying this function might be subtly led astray? That seems a better guide.<p><i>(Earlier version posted on reddit: <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;59cq8r&#x2F;applying_the_linus_tarvolds_good_taste_coding&#x2F;d97pcrl" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;59cq8r&#x2F;applyin...</a> )</i>