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.
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.
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!
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).
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