What makes a good reusable module?
In the previous section, we looked at the minimum requirements for a reusable module. Let's now examine the ideal requirements for reusability. What would a perfect reusable module look like?
There are three things that distinguish an excellent reusable module from a poor one:
It attempts to solve a general problem (or range of problems), rather than just performing a specific task
It follows standard conventions that make it easier to use the module elsewhere
The module is clearly documented so that other people can easily understand and use it
Let's take a closer look at each of these points.
Solving a general problem
Often when you are programming, you will find that you need a specific task performed, and so you write a function to perform this task. For example, consider the following:
You need to convert from inches into centimeters, so you write an
inch_to_cm()
function to perform this task.You need to read a list of place names from a text file, which uses...