3 ms·
I totally agree, it’s about proving you’re clever rather than communicating ideas. Maybe for something hard like Linux kernel development this is a good thing b
by andy_ppp 6y ago
I totally agree, it’s about proving you’re clever rather than communicating ideas. Maybe for something hard like Linux kernel development this is a good thing but in most cases it just leads to messy code that people can’t understand or follow.
- m_mueller 6y agoWhile there certainly are such cases, I think here it’s just about being proficient in a language. Pointers, referencing and dereferencing are the bread and butter of any C code, and applying them in a way to reduce complexity is certainly something to strive for - if this isn’t readable then I’d argue the reader shouldn’t be touching the codebase anyways.
- andy_ppp 6y agoFortunately or unfortunately you don’t always get to decide who touches the code, so unless performance is a concern as it is in kernel development optimising like this in the day job will eventually lead people making mistakes. Basically I say be as explicit and clear as you dare, even at the cost of some CPU cycles.
- saagarjha 6y agoAdding extra dereferences is rarely performant. The example is written this way because it's more elegant, not because it's faster.
- metters 6y agoYou are right, for a c programmer this is bread and butter. The readability of the example would increase a lot with better named variables, however.
- commandlinefan 6y agoI've written code like the first example many times, and I always felt a little "dirty" for doing it - I could tell there had to be some way to avoid treating head as a special case, but I was too lazy to actually work out how. The author of the second example may be "clever", but he also didn't give up.
- R0b0t1 6y agoI was only ever taught the second, more concise one, so this discussion is kind of confusing. How is it not shorter and more explicit?
- alisonkisk 6y agoMany Programmers who don't use C are afraid of pointers and prefer superficially simpler (but overall more complicated) things like Java's abstraction towers, despite the extra expense.
- a1369209993 6y agoTo be fair, many programmers who do use C have that character flaw as well.
- tent3n3 6y agoWhat if someone only ever learns what looks to be too clever to you? You make it sound as if some universal utilitarianism exists. Everyone’s personal event log is going to look just different enough to make that unreasonable.