Visualize a Modular Design

The locate function that we created during spiking does everything. That’s perfect for its intended purpose—to gain insight into the problem at hand. However, the production code we write should not resemble the spike. A function that does a lot generally fails the single responsibility principle,[13] lacks cohesion, and has high coupling. Such code is often expensive and difficult to maintain; also, its behavior is hard to verify quickly.

There are multiple little functions waiting to spring out of that spike to make the design modular and code testable. Let’s visualize those little functions, each with a single responsibility and minimum dependencies.

The dotted boxes are the external dependencies and the solid ...

Get Test-Driving JavaScript Applications 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.