I've just started studying coupling metrics and I'm having a hard time understanding instability. I find the term quite misleading and I don't understand how it can really help me develop better software.
If I understand correctly, "instability" itself is not a bad thing: a package that is totally instable has no afferent connections and can change often without impacting other packages. On the other hand, it is particularly impacted by changes in its efferent packages.
But the point is, "How do I determine how much a package depends on others?" The given formula (Ce / (Ce + Ca))
does not make sense to me. Let's say I have an instability value of 0.5
: I can have 1 efferent and 1 afferent connection (1 / (1 + 1))
but also 100
efferent and 100
afferent connections (100 / (100 + 100))
. What does it mean that the instability is 0.5
in both cases?
In the case of 100 efferent connections instead of 1, I have many more chances that my package will break because I depend on many more packages. And with 100 afferent connections instead of 1, I have many more chances to break some other package that depends on my package.
Why seems to be usefult to know if a package is totally instable or totally stable, seems to me that any value between 0 and 1 does not give me a real sense of how much that code is coupled. I should have some "absolute" number, not something relative.
Am I wrong? Is there anything I'm not considering?
Update 24/11/2024
What confuses me is the apparent conflict between the common meaning of "instability" (changing often) and its meaning as a metric (depending on others). It seems that this metric measures the "desired" instability/stability, not the actual one. For instance, a domain package in a hexagonal architecture should have instability 0. However, even if I achieve this, it doesn't mean that it is truly stable! Ideally, I can change external adapters without impacting the domain, but if I'm in the early phase of a project or if my domain is evolving due to new business requirements, it will change often, breaking the external layers.
This situation is not ideal, but I wouldn't reverse the relationship (with the adapter being stable and the domain unstable) because it's the domain that dictates the changes to others, even if these changes happen frequently.
It seems to me that a more appropriate term could be propagability: how much a change in the component can propagate to others. This term does not suggest that the package is stable (not changing); rather, it indicates that if I change the package, I am willing to propagate those changes to its dependents.