5 ms·
Linus’ solution seems to add a layer of indirection, which I think is harder to grok than a simple condition.
by bigyikes 6y ago
Linus’ solution seems to add a layer of indirection, which I think is harder to grok than a simple condition.
- eloff 6y agoThere's no accounting for taste ;)
- coldtea 6y agoBut there should be ;)
- alisonkisk 6y agoThe cs101 solution adds an unecessary extra variable "prev" that you have to study to figure out what it means. That's harder for me to grok.
- lordnacho 6y agoBut there's comments that explain it, so I think it's okay. I wouldn't leave a thing that has a mix of &, *, and -> without saying what it was supposed to do, but he does explain it. I'm ok with clever code when it's explained in words.
- GuB-42 6y agoThere is no extra layer of indirection. The idea here is to make the "p" pointer point on the "next" field of the current element instead of at the structure itself. There is the same amount of indirection in both solutions. The first solution does pointer->structure->pointer, the "elegant" solution does pointer->pointer->structure. The reason the first one may be easier to read is because the C syntax "prefers" it, as it is a more common construct.
- threatofrain 6y agoIMO harder to initially acquire but easier to grok at scale. Imagine combing through the behavior of blocks of code with conditionals in a larger system.