Monday, August 20, 2018

Opposition in Code Qualities Tends to Be Illusory

Generally, when it seems like two code qualities oppose one another, it means something that you're missing a piece of the puzzle.

For instance, there are some who think that cohesion and encapsulation make code less readable. However, that's only the case for people who haven't trained their minds to think in terms of abstractions while coding. Improving the general knowledge and skill of the reader alleviates the readability "problem" in the code.

Likewise, there are those who think that cohesion and focus are the opposites of one another. This appears to be because the typical cohesion-improving operation is to separate one code structure in to multiple structures and the typical complaint about poorly-focused code is that related things are too dispersed.

Yet, cohesion is not about separating concepts. It's about maximizing the degree to which parts of a whole are related; separation of concerns is just a means to achieving that end. Furthermore, just because people who are complaining about focus are citing that concepts are too spread apart doesn't make that the real reason for poor focus.

More often than not, the real problem causing a focus-complaint is a hidden or misunderstood lack of cohesion. Usually a concept has been broken apart and "sprinkled" through several places rather than being isolated into its own class/method/whatever.

There is an action indicated by apparent opposition of two code qualities. It is not to make a compromise and call it "balance".

The action is to find what's missing and close the gap.