Code re-usability and knowledge of the product

It’s harder to know most of the code base than to know most of the product functionality

I do believe that would be true for most of the cases, unless the code-base we are talking about is too small. Knowing what happens where in your product, in a way gives you a handle, to be able to reach that snippet of code fast. It becomes more and more obvious, if the product is understood as collection of smaller, functional units. The more granularity in being able to break down the product into functional units, the more chances of being better able to see the similarities or the differences between those. It’s the similarities that can lead to the commonality at the code level. And exactly that’s where the possibility of code re-usability kicks in.

So though your job might not need you to play much with the product, it’s a good idea to play around and often tinker with it. It might help you to get to those reusable snippets of code, that will make you the lightning fast, smashing super coder.

 

If code has been written well,  functional components may very well be re-used

Well, even if you have a handle and you are able to reach to that snippet of code that makes up a functional unit, it’s crucial that the code has been well written. It literally boils down to how thoughtfully, not under pressure and not-at-all lazily, the interfaces have been written. Sometimes it might turn out to be class-level i.e. a particular class and all it’s methods are dedicated to doing one or the other task of that functional unit, such that, all the complexity is hidden. All the exposed methods have no or minimal side-effects. It takes some significant gray matter,¬†efforts, passion and practical futuristic vision to be able to write such code and make it a habit to be able to always write such code!

It would be ok, if you spend some extra time now and make an attempt to write that re-usable piece of code. You might get a hang of it sooner than you thought you would. In the long run, it would be work done well and will make you proud.

 

Organic and on-going…

You might not always have the opportunity to write-up that nice, reusable piece of code. Huh? I mean, sometimes you might be adding just few lines or changing few conditionals to some existing code base. What do you do in such situations? Curse all those who wrote it so bad in the first place! Well, other than that, it’s still good to have some practical solution to this problem, that would let you – as an individual or team, to organically change the code base and make it generic. There can be many reasons, why it was not written generic in the first place. As mentioned above, one of the requirement is – practical futuristic vision, this can be broken down into 2 parts – 1. practical, that is also so closely related to common-sense and 2. futuristic vision, that’s always going to be bit vague and unpredictable. Hence, it’s not very common for you to come across not-so-re-usable code base. In fact sometimes it might happen that you would come across your own code, after couple of years, that you now can see can be clearly improved. There’s another element I would like to touch with regards to writing reusable code – time you might have on hands to finish up the job! Solution to that problem though is – habit of writing reusable code. Once you are into that habit, most of the code base should turn out to be quite decent. Still, every time you revisit those code points, the chances of you finding something that can be improved are very high.

Reusability should increase organically and should be an on-going part of coding practices.

Advertisements
Code re-usability and knowledge of the product