Chapter 9. Keeping things lightweight
This chapter covers
- Using complexity measurements to identify code to refactor
- Python language features for breaking up code
- Using Python language features to support backward compatibility
In your software development, you’ll remain vigilant about separating concerns, but you’ll generally wait until a sensible organization presents itself in order to avoid creating the wrong abstractions. This means your classes will generally grow bit by bit until they become unruly.
This is quite like the art of training a bonsai tree; you need to give the tree time to grow, and only after it tells you where it’s headed can you encourage it down that path. Trimming the tree too often can stress it, and forcing it into an unnatural shape may stunt its ability to thrive.
In this chapter, you’ll learn how to prune your code to keep it healthy and thriving.
Many an online forum on software maintenance contains questions of this nature. I sometimes wonder if we keep asking because we think eventually we can transcend to some new plane of understanding, where the answer was obvious all along. Each ensuing discussion thread contains a mix of opinions, anecdotes, and occasional data points.