Tuesday, November 4, 2008

Clean Code

Now that my team is working on some big and exciting development tasks for our Eclipse-based product, there is no better reading than Clean Code by Uncle Bob, the book that the Toronto Design Patterns Study Interest Group has chosen to read for this season.

Currently, I am working on a task that involves consolidating the model for our business process editor. Due to the adoption of GEF, our product has been running with two parallel models, a new one based on GEF and a legacy model that does not follow an MVC architecture. As a result, there is a lot of code duplication and dead code.

While I am working on the task previously mentioned, I have found how easy is to write bad code. Although, it is not hard to write clean code as a personal activity, it is harder to provide a sustainable policy for improving existing code as a collective activity. A fundamental rule in this policy is nicely described by Robert Martin’s book. In Chapter 1, he makes reference to the Boy Scout Rule: “Leave the campground cleaner than you found it”

In conclusion, the key point is not just to write clean code, but to polish existing code and leave it cleaner than how we found it. The benefits and advantages of clean code are widely discussed in the book, however my suggestion to you is to not commit code to your versioning control repository if your changes do not leave the code cleaner than you found it. Believe me, it will make your professional life easier.

Feliz coding,
Pablo