2 ms·
> "which always manifests itself as terseness as if lines of code were expensive)" They are expensive! Your code maintained years in the future, every develope
by jodrellblank 6y ago
> "which always manifests itself as terseness as if lines of code were expensive)"
They are expensive! Your code maintained years in the future, every developer has to potentially read every damn line.
The alternative to "clever" code isn't Java and FactoryFactoryFactories, it's short clear code, which is different from short codegolfed code. The main difference is nicely designed libraries and abstractions.
- jodrellblank 6y agoFor example, right now it's Advent of Code, day 6. The puzzles are still reasonably simple. Have a look around today's Reddit thread where people can post their answers: https://old.reddit.com/r/adventofcode/comments/k7ndux/2020_day_06_solutions/ https://old.reddit.com/r/adventofcode/comments/k7ndux/2020_d... These are self-selected people, free to use a language of their choice. Ask yourself some questions: - Which of these do I think is "most readable" vs "least readable"? - Which of these am I happy is correct, and bug-free as far as it goes? - Which of these would I like to make a change to, confident that it won't break? - Which took the author most / least time? - If I could only pick one to run on my puzzle input and submit the one answer which came out, which of these would I pick? - Which of these would I like to maintain long term? Another way to see the same ideas is to pick a task on RosettaCode - https://rosettacode.org/wiki/Category:Programming_Tasks https://rosettacode.org/wiki/Category:Programming_Tasks - and see how much / little code people write in various languages to solve the same problem. IMHO it isn't "the longest one" that is clearest, by a long shot. Nor the golfiest one. But it tends to be the shorter ones done in languages that have higher levels of abstraction, more libraries, nicer looking naming, more standard patterns.
- paulmd 6y agoyour comment about "short" vs "code golf" gets to the point of the comment you are responding to, which is one that Linus is downplaying - not all lines of code have an equal "cost". Potentially, using a code-golf implementation where you're using pointer-to-pointer to get rid of a single, easily understandable "special case", is more "expensive" in coder-time than just using the standard off-the-shelf linked-list that (even Linus admits) everyone knows from their data structures 110 class. Because now every developer who ever reads that bit of code for years into the future, now has to understand your code-golf solution, how it works, why it was done, and the implications for the rest of the code. Whereas they could probably skim the "standard" solution and say "yes, that is a standard linked list" and move on to solving the actual problem instead of trying to understand the code golf. In many cases: your clever solution isn't solving a difficult enough problem that it's worth the cleverness, because cleverness is often expensive. edit: I agree elsewhere that this is probably a question of "vocabulary" and whether a particular bit is "clever" or "code golf" depends on your particular team.