You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VariableHardUsage is an index used to evaluate the frequency of use and scope of local variables within a function. This measure is calculated based on the variance of the line number of references to the same variable and the frequency with which the variable is assigned.
@@ -95,31 +94,30 @@ VariableHardUsage is an index used to evaluate the frequency of use and scope of
95
94
96
95
* For each variable used in the function, retrieve all line numbers where the variable is referenced.
97
96
98
-
2. Calculate the average of the line numbers.
99
-
100
-
* Calculates the average of the line numbers obtained. This is obtained by dividing the sum of the line numbers by the number of references.
97
+
2. Calculate deviation based on first occurrence.
101
98
102
-
3. Calculate VariableHardUsage.
99
+
* For each reference, computes the difference between the line number and the line number of the first occurrence of the variable.
103
100
104
-
* Calculates the absolute difference between the line number and the average line number for each reference.
105
-
* If a variable is assigned, the difference is multiplied by a factor (2 by default).
106
-
* Sum all these values to obtain VariableHardUsage.
101
+
3. Applying coefficients by assignment.
102
+
* When a variable is assigned, the difference is multiplied by a coefficient (2 by default). This is to account for the effect of the assignment on the frequency of use of the variable.
103
+
* Calculation of VariableHardUsage:.
104
+
* The VariableHardUsage is obtained by summing all these deviation values.
107
105
108
106
### Example
109
107
110
-
For example, suppose there are three reference points in a function, each with line numbers 10, 20, and 30, where some assignments are made and some are not made. In this case, the average row number is 20.
108
+
Suppose, forexample, that there are three reference pointsin a function, each with line numbers 10, 20, and 30, and that some assignments are made and some are not made. In this case, the line number of the first occurrence is 10.
111
109
112
-
* Reference A: Row 10, with assignment
113
-
* Reference B: Row 20, no assignment
114
-
* Reference C: Row 30, with assignment
110
+
* Reference A: line 10, with assignment
111
+
* Reference B: line 20, no assignment
112
+
* Reference C: line 30, with assignment
115
113
116
114
In this case, VariableHardUsage is calculated as follows
VariableHardUsage is thus calculated as a measure of the frequency of use and scope of a variable. This metric can be used to quantitatively evaluate the usage of local variables within a functionandhelp improve code readability and maintainability.
0 commit comments