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. Not that I've never abused addresses like this. But having written this multiple times, I currently prefer something like this: remove_list_en…
Like Linus example, this is just an example too and does not cover or comment on all the issues, so there are still elephants lurking in the shadows, just to name a few: - Can entry be NULL? (segfault) - Can head be NULL (list is empty)? (segfault) Since the Linus example has the apparent precondition that the entry to be removed must be present in the list, there are no segfaults with proper API use. Since your code…
Applying the Linus Torvalds “Good Taste” Coding Requirement
81–90 of 302 posts
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#82I think "competitive" (i.e. solving algorithmic challenges for fun) coding really gives you some insight into how to write code that's short and to the point. The user with the most reputation on LeetCode, for example, consistently posts solutions that are surprisingly short, efficient, and readable. https://discuss.leetcode.com/user/stefanpochmann (some random examples) https://discuss.leetcode.com/topic/18731/7-lin…
The code might be short and to the point, but it definitely is not easy for me to understand! The code feels like a bit like clever perl one-liners.
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#83I 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. Not that I've never abused addresses like this. But having written this multiple times, I currently prefer something like this: remove_list_en…
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#84Earlier quoted context omitted.
Absolutely. Further, I would consider Linus's one-liner 'indirect=...' to be 'clever' code. If I were reviewing it, I would want it expanded into more obvious code as it requires too much cognitive overhead to parse.
Agree on the cognitive overhead. People will and are arguing that "it is kernel code, it should be complicated" but I really think this is backwards. Because it is low level and debugging is really cognitively intense and difficult at this level the code should be even clearer and easier to understand.
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#85I was given a piece of advice very early on in my career that I've always been grateful for, which is fundamentally the same as this. IF and FOR are both code smells. One case of this is just simplifying loops with some functional goodness var listOfGoodFoos = new List (); for(var i = 0; i VS return listOfAllFoos.Where(x => x.IsGood); But perhaps a more interesting point is it can also be a a sign of DRY gone wrong -…
I definitely agree with this, but note that the semantics in your code are different from those in Linus's example - your code filters out ALL matches.
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#86Earlier quoted context omitted.
Agree on the cognitive overhead. People will and are arguing that "it is kernel code, it should be complicated" but I really think this is backwards. Because it is low level and debugging is really cognitively intense and difficult at this level the code should be even clearer and easier to understand.
People aren't arguing kernel code must be complicated. People are arguing that dealing with pointers should be second nature to kernel developers, so the lines of code causing you and me congnitive overhead should be second nature to a kernel Dev.
This code is inherently too complex. it should be simplified
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#87I think the problem I have is that a lot of people use Linus's examples and stories as justification for their own suboptimal interpersonal skills, overly-clever code that only they understand, but without the same level of brilliance or track record to justify it.
Ultimately I think Linus's contributions to Software are pantheon, but he should not be looked to for imitation or lessons. His lessons for success are detrimental to the vast majority of software engineers.
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#88Earlier quoted context omitted.
Like Linus example, this is just an example too and does not cover or comment on all the issues, so there are still elephants lurking in the shadows, just to name a few: - Can entry be NULL? (segfault) - Can head be NULL (list is empty)? (segfault) Since the Linus example has the apparent precondition that the entry to be removed must be present in the list, there are no segfaults with proper API use. Since your code…
I can't see why the code from akkartik would segfault when entry is NULL? What am I missing?
If entry is null and head is valid segfault on line 10.
--edit--
As pointed out by my esteemed colleagues below, I didn't read the loop conditional properly. Only the first fault applies
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#89I don't know how to reconcile Linus's track record is of indisputable brilliance and success (I use Linux and Git on a daily basis and am eternally grateful for both), with the fact that I would absolutely DESPISE working with a peer with the kinds of attitudes and opinions on coding that Linus has. I think the problem I have is that a lot of people use Linus's examples and stories as justification for their own subo…
Re: Applying the Linus Torvalds “Good Taste” Coding Requirement
#90> it only performed 256 loop iterations, one for each point along the edge alarm bells There are only 252 points along the edge. This code will act on each corner twice. If you were performing an operation like `+= 1` on each edge element, this code would be wrong. When you copy and paste it later and change all the `= 0` to something else, you might end up with an unfortunate surprise. Once I saw this mistake in the…
for (i = 0; i
This way, for every row/column, the loop acts on all but the last cell, which is actually the first cell of some other column/row.