3 ms·
I agree with you that moving the conditional to the beginning as an early exit keeps things simple, and while I don't see anything unusual about a 'while' loop
by tempestn 10y ago
I agree with you that moving the conditional to the beginning as an early exit keeps things simple, and while I don't see anything unusual about a 'while' loop and feel they have their place, this 'for' definitely works well.
I would make one small tweak, replacing this line
prev->next = prev->next->next;
with
prev->next = entry->next;
Just makes it a bit more straightforward to understand (as well as infinitesimally more efficient).
- akkartik 10y agoYes, I'd be ok with a `while` that checked for the end of the list: https://news.ycombinator.com/item?id=12798192 https://news.ycombinator.com/item?id=12798192 I really try not to be a nazi about this sort of thing. Very few things matter enough to get into a HN conversation about "taste".
- tempestn 10y agoTotally, it's not about the one right way to do something. I do think there's some value in putting thought into how to write.. maybe "clean" code would be a less charged word than tasteful.