3 ms·
> both versions ignore an elephant in the room: defensively dealing with `entry` being absent from the list. Indeed, both versions really have a poor taste. Bo
by dwenzek 10y ago
> both versions ignore an elephant in the room: defensively dealing with `entry` being absent from the list.
Indeed, both versions really have a poor taste.
Both are code snippets which can only work under very restrictive assumptions.
The main argument `head` is implied and the `entry` to be removed must be present.
Such piece of code has to be duplicated and tuned for every list and use case.
I even wonder why Linus bothered to show this example, while he leads one of the most famous software masterpiece.
- mobiuscog 10y agoThis isn't an API though. 'head' is fine being implied, and if 'entry' doesn't exist, why is it being passed in ? That's a further code 'smell' to follow up. Sure, you need to be massively defensive if you're writing an API or boundary, but within an owned codebase, if you're eliminating edge-cases, you should follow them all the way up. tl;dr if you're calling remove_list_entry, only do so if you have an entry. Or course, I'm not Linus, so I have no idea of his thought process.