The Cost of Code Reuse Abuse
Join the DZone community and get the full member experience.Join For Free
oddly enough, while i’m sleeping or in some zombie state while attempting to sleep, i often feel like the ideas i have while in that state are the best thing ever and could possibly solve all the worlds problems. but then i wake up, and try to recall those thoughts and realize… nope, just shit.
but i think last night i was stirring up something in my head that has some merit, and something i’ve been thinking about for a while, inspired by a blog i read by udi dahan a while back (not sure how a blog post from 09 prompted me to think about this just now…). to wit, the idea that “code reuse” is the goal of many recent architectural styles, software methodologies, and “#bestpractices”. that if we can just “reuse” code, that we save on the “cost” of developing software, and thus can get to delivery faster.
in fact, that’s nonsense.
and udi dahan does a great job of explaining the differences between “use” and “reuse” in his blog post from a while back. his point is that code “use” is that of the generic kind: frameworks, common utility libraries, etc. that “reuse” is much more domain specific: business logic. furthermore, the true cost of delivering software lies in things other than writing code. he says
there’s the time it takes us to understand what the system should do. multiply that by the time it takes the users to understand what the system should do :-) then there’s the integrating that code with all the other code, databases, configuration, web services, etc. debugging. deploying. debugging. rebugging. meetings. etc.
yep. and he starts to get toward how dependencies on the “reuse” type of code is expensive:
it’s to be expected. if you wrote the code all in one place, there are no dependencies. by reusing code, you’ve created a dependency. the more you reuse, the more dependencies you have. the more dependencies, the more rebugging.
yep. code use, sure that’s okay. code “reuse”, that should raise eyebrows and there should be some pushback. and let me take this one step further.
once we step into the world of microservices where each service should own its purpose, code, logic, entities, etc (think, autonomous components, bounded context ), we have to think “how do we reduce our dependencies” not, “how do we share all this crap code that i wrote”.
one thing i’ve seen is people trying to make their business logic more “generic”. oh, then using/reusing is all good, right? this is hugely wrong!! don’t do this! business logic is supposed to model a business process in very specific way. if you try to “generecize” everything, you’ve now got ambiguity, a loss of expression/intent, and this ends up dramatically increasing technical debt !!! not to mention, the reason for making things more generic is reuse… so now you’ve spread this crap throughout your code/services/components/architecture. and now your cost of change has gone up. and one thing we’re trying to do is reduce the cost of change with our antics!
not to mention, writing generic code is actually quite difficult. if you’re starting a new project by writing a framework or some generic code, you’re doing it wrong and you need to just stop .
Published at DZone with permission of Christian Posta, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.