BecauseBecause, applied to your example:
- (+ flexibility) if you ever had to change the behavior of the
doStuffX, you'll want to kill yourself or whoever wrote it,+ readability
Less code often translates to less noise. (not always...)
- (+ extensibility) if you had extracted the distinct parts to a data-structure of your choice and then just iterated over it by calling a generic
doStuff, you could just as well add one line in your data structure where you want a new entry, or remove one, and changing the behavior will just mean editingdoStuff+ flexibility
If you ever had to change the behavior of the
doStuffX, you'll want to kill yourself or whoever wrote it, - (+ cost efficiency) less code
+ extensibility
If you had extracted the distinct parts to a data-structure of your choice and then just iterated over it by calling a generic
doStuff, you could just as well add one line in your data structure where you want a new entry, or remove one, and changing the behavior will just mean editingdoStuff. Easier to maintain. + cost efficiency
less code here means:
- => less development => reduced cost
- => less probability for bugs => less support time => reduced cost
- (+ possible managed optimization) depending on the language, the compiler/interpreter might have a bigger chance of determining that generic
doStuffdoes always the nearly identical things often one call after another, and could inline it or attempt to optimize it. Probably wouldn't for X variations ofdoStuffX)+ (possible) managed optimization
Depending on the language, the compiler/interpreter might have a bigger chance of determining that generic
doStuffdoes always the nearly identical things often one call after another, and could inline it or attempt to optimize it. Probably wouldn't for X variations ofdoStuffX. - (+ testing and quality) testing is easier:
doStuffneeds testing, and that's it (well, not exactly, but that covers already _more. Only its IO expectations vary and need to be tested under different conditions, but it's still a lot easier to test (and more maintainable) than all the variations ofdoStuffX+ testing and quality
Testing is easier:
doStuffneeds testing, and that's it. Well, not exactly, but that covers already more. Only its IO expectations vary and need to be tested under different conditions, but it's still a lot easier to test and more maintainable than all the variations ofdoStuffX.
Overall this accounts for more maintainable code and an improved development efficiency for your team, and it is one of many good practices to help you produce more robust and dependable software.