Code Karma


Release time is round the corner. Your mind is bent on getting done with those last chunks of code. Gone is most potential for optimization. Three lines of your usually-optimized code now expand into ten lines of unoptimized piece of rush affair. A relaxed full-meals is now turned into a fast-food breakfast. This is possibly when your code accumulates lots of bad karma. This bad karma will continue to haunt you (& the product) in the future.

This could take the avatar of, say, bugs or productivity loss, when you later attempt to extend that karma-accumulated code, or even worse, contribute to delays in future code deliveries.   

It is arguably believed that any action (or inaction!) accumulates karma in life. So it is true with code too. Each line of code, and each non-line(!) of code accumulates karma.  

Code karma can lead to a vicious cycle. You wrote that feature in a hurry consoling yourself that you would rewrite it tomorrow. But, as we all know, tomorrow never comes! Now, some good amount of bad karma is sitting in that feature-code. Years later (and remember, that tomorrow never came yet!), you are asked to build an enhancement to the bad-karma’ed feature. You are again close to the deadline. No looking back. You write the enhancement on top of the same bad-karma’ed-code. There you go! You have now accumulated more bad karma, because the enhancement you wrote has made things worse because you wrote it on top of the same code. Now, it is going to be even more difficult to attain code nirvana for that feature’s code!

How many times have you done this? You had written really long methods. No time to waste(?) in modularization. Then later you had to do many parts of the same method again but with some variations. Now, you have no time to go back to that method, modularize it and re-use the existing modular parts. Instead, you just copy-paste that method, delete the irrelevant lines and you are done. Not having written the method as modular (which was bad code karma) has led to more bad code karma. Now, you have more than one method duplicating pieces of code.

 

Ah! ‘copy-paste’! Reminds me! 

Code karma can be contagious! When you copy-paste code from, say stackoverflow, you inherit the code-karma of that originating developer. It becomes more important especially when you code for open-source or, say, an API. This is because the code-karma, that you injected into the code, is now going to spread to a greater number of products who use your open-sourced-code or API! There should more than just a ‘-‘ (hyphen) between ‘copy’ and ‘paste’! There needs to be, between them, a really strict policeman who would not allow (code from ‘copy’)=(code that is ‘pasted’)! 🙂

 

The converse is also true. Those beautifully crafted lines of code which you wrote with lot of love still stands strong across versions, without needing much modification and without troubling you with bugs! 

Good code karma leads to more good code karma. It’s similar to what we feel when we goto a dirty place ; we don’t mind dropping the chocolate wrapper in such a place. Whereas, if a place is truly clean, we would want to maintain its cleanliness if not contribute to improving it.

 

As you mature as a software programmer (the evolution we spoke of, earlier), it is important to be aware of the karma you inflict into the product when you code it. Awareness is the first step to avoiding/reducing bad karma, and also path to convert bad karma to good ones!

Love to hear your thoughts!