Discerning Intent

We did a couple of things in this chapter. The obvious one is that we took a common—although sometimes controversial—design pattern and broke down how to test it while preserving the essence of its intent. More importantly, though, we recognized that some of the patterns we have been taught to use without question require closer inspection to test. To take this a step further, using accepted design patterns idiomatically—as a chunk6 or out of habit—at a minimum complicates your testing—perhaps unnecessarily—and can unintentionally entangle concerns.

6. “Chunking” is a concept in the study of second-language acquisition. Effective language learners acquire “chunks,” or sequences of words, as a unit rather than limiting their learning to the fundamental building blocks of the language. Often, these chunks are idiomatic, ritualistic, or difficult to parse, and can seem quite strange when used inappropriately or inaccurately. Increasing levels of abstraction and larger units of design such as design patterns are the chunks of the programming world, with the same benefits and perils.

You need to make sure any entanglement of concerns is fully intentional and justified by the costs. Your tests will show you where you have mixed concerns. Your fixtures will be unwieldy. Your tests will be long and complicated. Your tests may seem impossible to write due to that one seemingly important design decision.

When this happens, you have encountered a code smell through your tests. Your tests express or want to express an intent that you find hard to satisfy. You should consider changing your design and separating your concerns in a way that clarifies the intent of your code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.200.14