I assume the author of this article had spent too much time being confused by the ‘Windows Subsystem for Linux’ nomenclature.
Linus Torvalds' good taste argument for linked lists, explained
241–250 of 339 posts
Re: Linus Torvalds' good taste argument for linked lists, explained
#242Earlier quoted context omitted.
That's a pretty big freakin thing to leave out, though. Code that depends on its context is, some would say, bad.
This is why Linus' code shouldn't be copied verbatim and used in the real world. The Kernel is an extremely isolated and contained system. At the very least, the code should add comments on the the assumptions that are vital...otherwise n00bs will copy the code as gospel and run into all sorts of problems.
Re: Linus Torvalds' good taste argument for linked lists, explained
#243Re: Linus Torvalds' good taste argument for linked lists, explained
#244Re: Linus Torvalds' good taste argument for linked lists, explained
#245 void remove(IntList* l, IntListItem* target) {
if (l->head == target) {
l->head = l->head->next;
return;
}
IntListItem* prev = l->head;
while (prev->next != target) prev = prev->next;
prev->next = prev->next->next;
}
Skimming the comments here, I was surprised not to see an equivalent piece of code mentioned. To me my code is more readable than both of the first and second examples presented in the article. Does that mean my taste is peculiar?Re: Linus Torvalds' good taste argument for linked lists, explained
#246Earlier quoted context omitted.
My taste is that function level comments describe the "what" and inline comments describe the "why". So at a function level the comments is giving a highlevel description to the reader as to the functionality contained, and at the line level comments exist only to say describe the programmers intentionality, why it was implemented this way rather than some other way. I have generally found (there are always exception…
The main takeaway here might be that two 25 year veterans both make function level and line level comments. The particulars are somewhat of a matter of flavor preference :)
The particulars matter.
Re: Linus Torvalds' good taste argument for linked lists, explained
#247Re: Linus Torvalds' good taste argument for linked lists, explained
#248I'm not sure why the article removed comments from the code and replaced variable names like "indirect" with "p". Here are the two code samples verbatim from Linus's presentation: remove_list_entry(entry) { prev = NULL; walk = head; // Walk the list while (walk != entry) { prev = walk; walk = walk->next; } // Remove the entry by updating the // head or the previous entry if (!prev) head = entry->next; else prev->next…
Hacker news would benefit from code blocks.
this line has 4 spaces in front of it.
What Hacker news could use instead are quote blocks. Now people often use the code blocks as quote blocks.Re: Linus Torvalds' good taste argument for linked lists, explained
#249The following is the code I wrote before reading the example pieces of code. void remove(IntList* l, IntListItem* target) { if (l->head == target) { l->head = l->head->next; return; } IntListItem* prev = l->head; while (prev->next != target) prev = prev->next; prev->next = prev->next->next; } Skimming the comments here, I was surprised not to see an equivalent piece of code mentioned. To me my code is more readable t…
There are two cases here (1. when the target is at the front of the list and necessitates changing the head of list, and 2. when the head doesn't need to be changed.) You handle both the cases separately.
Both the classical and the "elegant" versions are worse than this one.
Re: Linus Torvalds' good taste argument for linked lists, explained
#250Let's draw a list IntListItem -> IntListItem -> IntListItem and then draw the position of the list head: IntList -> IntListItem -> IntListItem -> IntListItem You can see that the if-branch in the cs101 answer comes because there is a ('virtual') element of the list (the IntList head) that is different from the other elements of the list. If we were to make them the same (C# code): interface IListItem { IntListItem Ne…