3 ms·
Fewer lines of code don't always mean simpler code. Sometimes it means cleverer code (read: harder to understand and maintain). Three quotes I frequently repeat
by hliyan 10y ago
Fewer lines of code don't always mean simpler code. Sometimes it means cleverer code (read: harder to understand and maintain). Three quotes I frequently repeat in this context:
1. Duplication is better than the wrong abstraction
2. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
3. Code must be written for people to read, and only incidentally for machines to execute
- jomamaxx 10y agoYeah. This. I think that sometimes people that 'more compact code' is what we mean be 'less code' and it's really not. I think the differentiation is at the algorithmic level: it's not algorithm density, it's 'system clarity' that's key. I find a nice rule of thumb is 'don't code two steps ahead'. Just because you may think you need to write a couple of 'duplicate lines' here and there, don't even bother abstracting for it. Wait until there's a few more. Software people tend to outsmart themselves and build way ahead of what they need. I think it's better to 'discover' the minutia of architecture than to plan, it all but the grandest elements. An artists drawing a figure will 'sketch out the form' - that's the basic architecture you can do up front, but it lacks detail. The 'art' comes out incrementally piece by piece. And the human aspect: it should hopefully read like English to a casual observer. It also helps to think of it from a business perspective: + What the code does is an economic asset + But actual lines of code are a cost centre and an ongoing liability.
- JamesBarney 10y agoYeah when I find duplicated code I always ask myself is this duplicated because this is representing the same domain concept in two different places? Or is it duplicated by coincidence? I'm much more aggressive about refactoring the former than the latter. When I was first starting off it was always hard for me to tell the difference so I abstracted a lot of things that I shouldn't have, and you could tell from the terrible method names that follow leaky abstractions.
- elliotchance 10y agoOne of my biggest pet peeves is code duplication from lazy copy/pasting. I find it's a good exercise for myself to sometimes pretend like the copy/paste key are not available to me. I had to think about the first one for a moment, but I do agree. It's better to abstract later with greater knowledge than the much more difficult task of trying to debug or fix it later. It's an outstanding list and great rules to work by!
- neurostimulant 10y ago> I find it's a good exercise for myself to sometimes pretend like the copy/paste key are not available to me. This is a great idea! I'll try to remember this whenever I have the urge to lazily duplicate some code (which is quite often now that I think about it).
- ArkyBeagle 10y agoBut you have to have a model for various costs ( and risk is a cost ) of copypasta vs. Well-Organized-Completely-Normal-Independent-Code.