Chapter 10. Packages

In this chapter, we get to start having fun, because we get to start talking about software design. If we’re going to talk about good software design, we have to talk about Laziness, Impatience, and Hubris, the basis of good software design.

We’ve all fallen into the trap of using cut and paste when we should have defined a higher-level abstraction, if only just a loop or subroutine.[133] To be sure, some folks have gone to the opposite extreme of defining ever-growing mounds of higher-level abstractions when they should have used cut and paste.[134] Generally, though, most of us need to think about using more abstraction rather than less.

Caught somewhere in the middle are the people who have a balanced view of how much abstraction is good, but who jump the gun on writing their own abstractions when they should be reusing existing code.[135] Whenever you’re tempted to do any of these things, you need to sit back and think about what will do the most good for you and your neighbor over the long haul. If you’re going to pour your creative energies into a lump of code, why not make the world a better place while you’re at it? (Even if you’re only aiming for the program to succeed, you need to make sure it fits the right ecological niche.)

The first step toward ecologically sustainable programming is simply this: don’t litter in the park. When you write a chunk of code, think about giving the code its own namespace so that your variables and functions don’t clobber ...

Get Programming Perl, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.