Saturday, September 8, 2018

Writing a REUSABLE code.

Any code can be reused in a way or another we call it as reusable code. A programmer should explicitly make the code reusable by taking into account other situations of the code usage.

I would make it a best-practice of my Software Developer career that I will always write a reusable code. The code that helps and minimizes the effort and time which reduces the instances of coding from scratch.

Write the code for other people to read. This means a combination of good names, good comments, and simple statements make code clean and understandable. Sometimes programmers write complex single lines of code that do many things. But instead of writing one line of code that is difficult to understand we should write 5 lines of simple code that people can follow. Because today memory is plenty and cycle times are fast, this would not take more than a minute for executing 5 lines of code.

Reusability is rarely a worthwhile goal in itself. Rather, it is a by-product (secondary product) of writing code that is well structured, easily maintainable and useful. We need to into account that if we start with bare requirements of any project, we will find that the code will be clean, tight and elegant. When we'll work on another project that needs the same functionality, we can naturally adapt our original code. If we need to change something, then we can just create another piece of code, another class, another library, etc... it helps the other developers who are working in the same application.

Comments are more important. everything we write in comments should point to the function of the code and why we are writing that. What it will do? Everything that might be confused when we come back to the code next time will have comments clearly written. We can within no time can figure out what were we doing the last time and save hours of time.

Finally, Programming is performance; we should be aware of who our audience is. "Code as if the person who ends up maintaining our code is a violent psychopath (having a mental disorder) who knows where you live."

No comments:

Post a Comment