Introduction: Why Reuse Code?

Resourceful Code Reuse — by Dmitry Zinoviev (7 / 20)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 About the Software | TOC | C vs. Python 👉

Despite its name, modern computer science isn’t just a science — it’s also a 200-year-old arcane art, if we accept Charles Babbage as the first theoretical computer scientist. It comes loaded with legends, anecdotes, apocrypha, unwritten rules, and other words of wisdom. One example is the proudly found elsewhere (PFE) or invented elsewhere (IE) predisposition: if the wheel has been already invented, you shouldn’t design it again without a strong reason but reuse the existing design. PFE/IE is a special case of the more general philosophical Occam’s razor principle: entities shouldn’t be multiplied without necessity.

As far as this book is concerned, both Occam’s razor and PFE/IE apply to a simple concept: you should write a large code fragment only if you or someone else hasn’t written that code fragment before. If the fragment has been written, use it again — reuse it.

Several reasons exist for code reuse:

  1. Code reuse puts into practice the advice of none other than William of Occam (or Ockham, depending on whom you ask). If you and I were philosophers, that alone would suffice.
  2. Code reuse improves your productivity. Code fragments that you develop to deal with frequently occurring tasks (for example, reading from and writing to JSON files or supporting heterogeneous arrays and maps) become parts of…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.