Saturday, November 6, 2010

Code Reuse Myth

Code Reuse Myth

Allan Kelly makes some interesting points about code reuse. He argues that code reuse is a bad development goal, since most code designed for reuse is never actually reused. Often, developers want to create reusable code, not because they think the code will be reused, but because the final code will be better engineered. Specifically, the code will be have properties like low coupling, modularity, and testability. However, creating "reusable" code costs a lot. Kelly thinks that it's something like 3 times more expensive.

I think that code re-usability should not be a direct goal of software architecture. It's silly for this to be a direct goal, if it's never a requirement. This is especially true because of the cost. However, code properties that accompany re-usability(like low coupling) should be software architectural goals. This has real benefits to everyday development, and has a side effect of creating code that can be easily reused, with minor modifications. This would probably cost a lot less, since not every component of the system needs to be abstracted to some generic, reusable code section. To make things worse, planning for everything to be reused is often over engineering. The resulting code is a nightmare to understand. Code that abstracts too much becomes much less clean, and as a result, much harder to work with.

Lesson: Plan to write code that is testable and well engineered, and you get reusable code. Don't plan to write reusable code that happens to have positive software architectural properties.

Also, hi

1 comment:

  1. This is true.

    However, I am inclined to believe that doing otherwise is going to run counter to Jesse's OCD.

    ReplyDelete