Connascence, why is it so important?

Connascence metric has its own website https://connascence.io/ where you can find detailed description and examples. In this post we will show why connascence is very important metric, we will visualize, condense and summarize the concepts so they are fast and easy to comprehend.

What is connascence?

Before we can understand importance of connascence, let’s understand what it is. Connascence is a software quality metric that describes different levels and dimensions of coupling, it is more descriptive and complete metric than coupling on its own. Coupling is a connection between presumably independent things, so that if one thing changes the other need to change as well in order to maintain correctness.

Simple example, given we have two functions and we change implementation of one of them, for example input parameter type. If we need to change implementation of the other function to keep code running correctly, we have coupling between the two functions. Connascence will describe how bad the coupling between the functions impact overall code quality. The lower connascence, the higher code quality.

Levels of connascence

There are nine levels of connascence being identified so far. The levels are grouped into two sets, static and dynamic. Static connascence levels are based on code and can be identified just by looking at the code. Dynamic connascence levels are based on execution and appear when code runs. Diagram below shows all the levels ordered from lowest on the top to highest on the bottom. Note, that any dynamic connascence is worse than any static. The higher level of connascence the harder and riskier is to introduce changes to code.

Connascence levels diagram

Properties of connascence

There are three identified properties of connascence:

  1. Strength. The higher level of connascence, the higher the strength. Example, the strength of connascence of Name is lower than the strength of connascence of Algorithm.
  2. Locality. It describes how close the coupled components are. The higher connascence locality, the better. Coupled methods that are in different modules are much worse than coupled methods within same module.
  3. Degree. It describes how many components are coupled. Example, if we change implementation of one component, how many other components do we need to change.

Connascence = Strength x Degree / Locality

Connascence properties diagram

Why connascence is so important for us?

We live in the world that changes every day, business processes adjust to new realities, new and better ways of doing things are discovered, new technologies and methodologies becoming available. Therefore, software needs to change to stay current with the reality.

High connascence undermines ability of software to change. The higher connascence, the more code we need to change, the costlier and more time consuming the change becomes. But it’s not only about time and money, the more severe level of connascence is, the higher probability of introducing new bugs while changing code, therefore risk of change is higher.

Code with higher connascence is harder to reason about and understand, therefore hard and dissatisfying to maintain. Teams that have to deal witch highly connascent code are less likely to attract new talent, making hiring process harder and employees retention lower.

It’s much easier to prevent high connascence than improve it after the fact. Therefore, we always need to keep connascence in mind while creating architectures, designing components, writing, refactoring and reviewing code. When we are faced with multiple design options, connascence should be considered as one of driving forces that influence our decision.

However, if we already inherited code that has high connascence we can get guidance on how to improve the code quality. Lowering level of connascence, localizing coupled components and reducing their number are the ways to improve connascence, hence code quality.

Pavel Hudau
Posts created 16

2 thoughts on “Connascence, why is it so important?

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top