The problem is that not only does source code not explicitly record a lot of the underlying thinking which goes into the design of the system (including how the computer application fits with the wider world outside the computer), but by definition the source code cannot record any thinking about properties which the system has implicitly or latently but which were not intentionally designed-in by the developer at the outset.
If there was some kind of analysis or metric, it is unclear how it would work except by analysing source code, which is not a complete record about the design of software.
Generally speaking, data processing is not merely about automating the calculation of certain values from others, but about automating the storage, retrieval, and movement of data, as part of how a system of doing business is organised and how the activity of a workforce is coordinated. That is, the simple movement of data to and from storage (either quickly on demand, or on the correct schedule), in exactly the form it was originally input by the user, is often just as useful as any calculations and transformations that may occur.
What is recorded by a computer in a business context is often things about the real world - either temporary facts about the state of the wider business operation, or about the events that have occurred or activities performed within the scope of that operation.
It is therefore inherent that there are "state changes" and "side effects" in the machinery which automates that data processing, because the real world consists of changing circumstances which that machinery is supposed to record - there is nothing remarkable or undesirable about these state changes per se.
The process of developing software and computerisation is often not just about fitting the workings of that software to suit what the system of doing business requires in terms of data processing, but also altering the system of doing business to better resemble a simple mechanical activity that is eligible to have records made about it, and eligible for computerisation.
What this all means is that, for the purposes of any analysis of software, the bulk of information that is clearly necessary for a rigorous analysis of what it does and why, is simply not recorded anywhere - insofar as we accept that source code doesn't even touch the sides of describing "how a business works".
Indeed the information is not even necessarily present in the minds of the developers. When you supervise the design of an application over a period of time, you often find that it works in a certain way that was arbitrary at the time those workings were first conceived, but later becomes particularly useful for a new purpose. You can also find the counterpart case, that an originally arbitrary aspect of a design later becomes highly inconvenient.
The point is that the software design clearly has certain properties set into it, the usefulness (or disusefulness) of which might become very clear to us when we try to do certain new things with it, but those properties may be introduced arbitrarily in the first place.
I dare say there are also properties which are useful and necessary right from the outset, but which are introduced only accidentally in the first place, and which the developer may not recognise the existence of unless these properties are upset by a change.
This makes it hard to safely change code without understanding the whole system
Yes. The need for whole-system understanding when designing systems, in order to design them correctly, is unfortunately the nature of the challenge.
A lot of people unfortunately approach this problem in a small-minded way by asking how systems can be broken up into smaller independent pieces that they can presumably more easily grasp. But there often are no smaller independent pieces.
There are actually two other possible strategies. One is to control the complexity of designed systems in the first place, so that they can be understood and readapted more easily.
Another is to accept the complexity but consider how to effectively reproduce whole knowledge and understanding about them. This might often involve teams or communities of people having a collective understanding and capability, rather than a single individual having it. This is traditionally the role of institutions like churches, trade guilds, and universities - the latter when they were organised around the needs of attracting and developing intellectuals, rather than around retailing credentials.
The point is to emphasise that there are known strategies for coping with complex man-made systems, they just don't involve getting the moon on a stick, but involve processes of education which become a significant form of work activity in itself (both for the teacher and the learner) and it involves a scale-out of brains in which multiple people have to be organised into one mind that works together on a problem.
But most systems have some amount of "accidental" state changes that aren't necessary, and that make the system harder to understand and to change.
Perhaps - I can't immediately think of an example in practice of "accidental" and unnecessary state changes.
It is obviously not that easy to identify them, otherwise you wouldn't need a metric - you'd just review the code. I presume one of the ways they "make the system harder to understand", is by these defects themselves being hard to understand - hard to understand what they do as part of the system, and whether they are necessary for the correct workings or not.
And how easy is it to change the software to drive out these accidental and unnecessary state changes once they are identified as defects?
It may not pay and dividends by identifying them more easily through metrics, if it is still then difficult to drive them out - as difficult as the difficulties they are said to cause for making other changes.