Code reusability, where they get it all wrong
In our industry, we talked so much about reusable code, which I really appreciate how we want to make things so simple, reusable and make a things more modular that we can build a great thing from the shoulder of the giant.
But still, I see there are many teams and many developers have some misconception about reusability, which I will explained how.
Simple concept is here:
When we talked about reusability, we want our team, other developers to “actually” reuse it
Yes, and this is so simple. We take a lot of effort, lot of works just to make sure our code will be reuse somewhere, be a part of a great product somewhere.
And then after we take so much work into make code reusable, many people look away from the core concept and become like:
Code is reusable when it is more modular, have less dependency, following OOP principle, following functional programming principle, etc.
I did not say that they are bad principle. Actually, all of these principle are good principle, but it’s just a tool, not a core concept.
What happen if you take this too far, and I’ve seen many team does this, is you write a code where there have a lot of beautiful structure, following the new trend, and nobody actually reuse it because they don’t know what actually you are doing.
And then again, in many teams, I’ve seen bad codes being copy-pasted all over the place. So, that bad piece of code is “actually” being reused. While your elegant piece of code can be use by you and only you. Yes, zero reuse vs. hundred copy-paste. Now may I ask which code have more reusability in the real-world?
Don’t get me wrong here, I perfectly understand how copy-pasting code is actually hurtful in the wrong run. My point is, code reusability is not all about elegant architect.
If you actually want to help other developer to actually reuse them, you need to do more than just writing an elegant code and expect everyone to reuse it. That’s not how the world works.
Simple advice is here: If you want your code to be reuse, make it easy to be reuse.
For the open-source community, the guy who create something like NPM, PIP, Bower actually did a great job to go far beyond “just write reusable code” and actually make the code reuse happen.
For the private team who still in development process: Please understand that code reusability is not just about writing good code. It also required mentorship and making sure everyone can reuse your code.
So if you want your code to be reuse, make it easy to be reuse and make sure everybody know how to reuse them. Teach them, tell them, take some mentoring as your job
Yeah, simple as that.
So, instead of just writing a good code and try to convince everyone (even go as far as debate) to reuse them, you should ask “Why you don’t feel like reusing my code” and try to understand him. Maybe he lack of knowledge we should share? Is it possible to help him to reuse my code.
Things go wrong when you take an ego too far and told yourself “Wow! this guy is too stupid to reuse my code”
Building beautiful reusable code is like building beautiful product. You actually need to make sure “user” (in this context, another developer) love to use it.
If it need some training, some coaching, that just how the world works. Just do it!! Presenting to them how easy your code is in some conference blah blah.
In the end, it’s all come down to you, do you actually want your code to be reuse, or do you just want to make an elegant code to yourself?
What you want is want you get anyway.