Chapter 8. Designing a Good API

What makes some code “good” and other code “bad”? If a piece of code functions properly and has no bugs, isn’t it good? Personally, I don’t think so. Almost no code exists in a vacuum. It will live on past its original application, and any gauge of quality must take that into account.

In my definition, good code must embody qualities like the following:

  • It is easy to maintain.

  • It is easy to reuse in other contexts.

  • It has minimal external dependencies.

  • It is adaptable to new problems.

  • Its behavior is safe and predictable.

This list can be further distilled into the following three categories:

  • It must be refactorable.

  • It must be extensible.

  • It must be written defensively.

Get Advanced PHP Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.