The Delusion of Reuse and the Rule of Three

I’m currently reading Facts and Fallacies of Software Engineering by Robert Glass. It’s definitely a worthwhile book, although I do have two criticisms:

  1. Someone really, really needs to buy Robert Glass a copy of Strunk and White’s Elements of Style. Or at least get him a decent editor. There’s some great information here, but his overly florid writing style gets in the way.
  2. Quite a few of the 55 facts and fallacies presented here will be old news to anyone familiar with the most popular books on my reading list for developers. For example, “Adding people to a late project makes it later.” That’s well understood, and Glass doesn’t cover enough new ground with these chestnuts to justify the two or three pages each one adds to the book.

That said, I am really enjoying the parts of the book that cover the more obscure topics. For example, the Rule of Three:

There are two “Rules of Three” in reuse: (a) It is three times as difficult to build reusable components as single use components, and (b) a reusable component should be tried out in three different applications before it will be sufficiently general to accept into a reuse library.

I have found this to be universally true in the projects I’ve worked on. If anything, I think this rule underestimates the cost: I believe writing a truly reusable class is an order of magnitude harder than writing a single use class. Sometimes the right thing to do is resist the urge to write “general purpose” solutions. Sure, it’s better in the long run to have a widget library you can use forever, but that doesn’t get your current project done any faster. Furthermore, how confident are you that the so-called “general purpose” solution you built will actually work for these… unknown future projects? Have you tried it?

You can’t know if you have a strong case for reuse unless you’ve tried – and possibly failed – to use that same bit of code on at least three different projects, with three different audiences.

Until you’ve invested the additional effort to implement that “reusable” code with different developers and different problem domains, all you have is the delusion of reuse. Be careful, because I’ve seen too many developers fall into this trap. Myself included.

Related posts

Complaint-Driven Development

If I haven’t blogged much in the last year, it’s because we’ve been busy building that civilized discourse construction kit thing I talked about. (Yes, that’s actually the name of the company. This is what happens when you put me in charge of naming things. Pinball

By Jeff Atwood ·
Comments

The Rule of Three

Every programmer ever born thinks whatever idea just popped out of their head into their editor is the most generalized, most flexible, most one-size-fits all solution that has ever been conceived. We think we've built software that is a general purpose solution to some set of problems, but

By Jeff Atwood ·
Comments

Today is Goof Off at Work Day

When you're hired at Google, you only have to do the job you were hired for 80% of the time. The other 20% of the time, you can work on whatever you like – provided it advances Google in some way. At least, that's the theory. Google&

By Jeff Atwood ·
Comments

Coding Horror: The Book

If I had to make a list of the top 10 things I've done in my life that I regret, "writing a book" would definitely be on it. I took on the book project mostly because it was an opportunity to work with a few friends

By Jeff Atwood ·
Comments

Recent Posts

Stay Gold, America

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood ·
Comments
The Great Filter Comes For Us All

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven’t any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don’t stop there – read the Story of Your Life novella it was based on for so much

By Jeff Atwood ·
Comments
I Fight For The Users

I Fight For The Users

If you haven’t been able to keep up with my blistering pace of one blog post per year, I don’t blame you. There’s a lot going on right now. It’s a busy time. But let’s pause and take a moment to celebrate that Elon Musk

By Jeff Atwood ·
Comments
The 2030 Self-Driving Car Bet

The 2030 Self-Driving Car Bet

It’s my honor to announce that John Carmack and I have initiated a friendly bet of $10,000* to the 501(c)(3) charity of the winner’s choice: By January 1st, 2030, completely autonomous self-driving cars meeting SAE J3016 level 5 will be commercially available for passenger use

By Jeff Atwood ·
Comments