- Step 1: Eliminate All Assumptions
- Step 2: Don't Be Afraid to Standardize
- Step 3: Live by the Golden Rule of Programming
- Step 4: Build Upon a Foundation of Smart Error Coding
To reuse code effectively, you have to write code that's worthy of reuse. "Reuse-quality" code must be flexible enough to accommodate the widest range of needs. It must be robust enough that the user doesn't have to risk his or her project on unreliable code. It must be standardized enough that the user can immediately understand what to expect from the code, how it works, and how to maintain it. Finally, it must be written efficiently enough to be cost-effective. If any of these requirements are not met, users will find it easier and faster to reinvent the wheel.
So how do you create reuse-quality code and still stay under budget?
Assumptions are the root of most coding problems, including a lack of reusability. One such assumption is "No one will ever need this again." If you start with that assumption, you'll never build reuse-quality code.
Every routine should be written as if it will be reused—even if it won't. Failure to do so undermines the level of consistency and standardization in the code, reducing quality and maintainability.
Eliminate other assumptions about how and when the code will be used. Develop each routine as a completely generic function.