Tuesday, April 29, 2014

Applying the 4 R's of conservation to Software Development

Refuse, Reduce, Reuse and Recycle. It works to reduce landfill, It also works to ensure our code and documentation does not end up in the virtual landfill and it is properly used by future generations

Here is how I relate it to code in particular, and as you will see, applying one makes it easier to apply the others. 

Refuse
Do not write code you don't need to write. This applies at different levels, here are some examples
  • Avoid automating one-off tasks
  • Before automating a process, ensure it has been properly re-engineered. A bad process automated is still a bad process
  • Always verify if you need to write new code or if something else already exists. This is: Don't write code that already exists just because you don't understand or like the existing code.
Reduce
When it comes to code, less is more. Less to maintain, less opportunities for bugs to creep in, easier to extend.
  • Don't write code you "may" need. Write it as you need it. This is also called YANGI (You aren't gonna need it)
  • The less code you write, the easier it is to refactor later as new needs arise.
Reuse
Reuse existing code. The likelihood that this is the first time you have faced a particular problem or that you are the first person facing a problem is fairly low.
  • Search around for existing code, either in the form of libraries, frameworks, the internet and your own code.
Recycle
Code for Reuse: Follow techniques that allow others to reuse your code.
  • Refactor existing code. If you used the second R, the existing code should be clean enough that extending it to fit the new conditions will be easier.
  • Identify patterns that emerge as you reuse code so you can identify when you can refactor the edisting code to create libraries, frameworks, code with dependency injection in mind, Expose extensible interfaces, etc.
You will see that if you and your team follow these R's, you will end up writing less code and having a clearner code base.

In future posts I'll go deeper into practices that directly relate to these 5 R's.

No comments:

Post a Comment