3 ms·
To me the main readability problem of the first example is that it does the head check as the last step rather then first step. Meaning we have to consider "wai
by im3w1l 8y ago
To me the main readability problem of the first example is that it does the head check as the last step rather then first step. Meaning we have to consider "wait, when is this null again".
The main problem with the last one is that it's not immediately obvious what the "indirect" represents. When it clicks that it is "the pointer to potentially update", it's pretty easy to understand.
- ummonk 8y agoThe 2nd one would be significantly more readable with explicit typing (to make it clear that you're dealing with a pointer to pointer). Though I think putting the head check at the beginning like you said will make the first example very reasonable (and relatively compact too). remove_list_entry(entry) { if (head == entry) { head = entry->next; } else { prev = head; while (prev->next != entry) { prev = prev->next; } prev->next = entry->next; } }