Applying the Linus Torvalds “Good Taste” Coding Requirement
I dunno, the first example seems unsatisfying. The original has that ugly condition, the "good" 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'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->next;
          return;
      }

      for (prev = head;  prev->next;  prev = prev->next) {
          if (prev->next == entry) {
              prev->next = prev->next->next;
              return;
          }
      }
  }
</code></pre>
There's still an `if`, but it isn't so bad since it's an early exit. What is "tasteful" about hiding the fact that one of the cases is <i>far</i> simpler than the other? There's conditionals and then there's conditionals. There's cases and then there'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 "taste", 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://www.reddit.com/r/programming/comments/59cq8r/applying_the_linus_tarvolds_good_taste_coding/d97pcrl" rel="nofollow">https://www.reddit.com/r/programming/comments/59cq8r/applyin...</a> )</i>