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 a localvariable within a function. This indicator is calculated based on the variance of the line number at which the variable is used and the frequency with which the variable is assigned.
90
+
VariableHardUsage is an index used to evaluate the frequency of use and scope of localvariables 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.
90
91
91
92
### Calculation Procedure
92
93
93
-
1. Obtain the line numbers of the variables:.
94
+
1. Obtain the line numbers of the references to the same variable:.
94
95
95
-
*Obtains the line numbers of all variables used in the function.
96
+
*For each variable used in the function, retrieve all line numbers where the variable is referenced.
96
97
97
98
2. Calculate the average of the line numbers.
98
99
99
-
* Calculates the average of the retrieved line numbers. This is obtained by dividing the sum of the line numbers by the number of variables.
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.
100
101
101
102
3. Calculate VariableHardUsage.
102
103
103
-
*For each variable, the absolute difference between the line number and the average line number is calculated.
104
+
*Calculates the absolute difference between the line number and the average line number for each reference.
104
105
* If a variable is assigned, the difference is multiplied by a factor (2 by default).
105
106
* Sum all these values to obtain VariableHardUsage.
106
107
107
-
### EXAMPLE.
108
+
### Example
108
109
109
-
For example, suppose there are three variables in a function, each with row numbers 10, 20, and 30, and that some assignments are made and some are not made. In this case, the average row number is 20.
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.
110
111
111
-
*Variable A: Row 10, with assignment
112
-
*Variable B: Row 20, no assignment
113
-
*Variable C: Row 30, with assignment
112
+
*Reference A: Row 10, with assignment
113
+
*Reference B: Row 20, no assignment
114
+
*Reference C: Row 30, with assignment
114
115
115
116
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