Skip to content

Commit 8baf3a7

Browse files
committed
update README.
1 parent 2f700c9 commit 8baf3a7

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

README.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,69 @@ VariableHardUsage is an index used to evaluate the frequency of use and scope of
186186

187187
### Calculation Procedure
188188

189-
1. Obtain the line numbers of the references to the same variable:.
189+
This tool calculates the **Variable Hard Usage** score for each **scope** (i.e., a function or method) based on how local variables are used. The calculation consists of the following steps:
190190

191-
* For each variable used in the function, retrieve all line numbers where the variable is referenced.
191+
---
192192

193-
2. Calculate deviation based on first occurrence.
193+
#### 1. Extract local variables in a scope
194194

195-
* For each reference, computes the difference between the line number and the line number of the first occurrence of the variable.
195+
For each scope $S$, extract all local variables:
196196

197-
3. Applying coefficients by assignment.
198-
* 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.
199-
* Calculation of VariableHardUsage:.
200-
* The VariableHardUsage is obtained by summing all these deviation values.
197+
$$
198+
V = {v_1, v_2, ..., v_m}
199+
$$
200+
201+
---
202+
203+
#### 2. For each variable $v_j$, identify lines where it is referenced
204+
205+
Let the variable $v_j$ be referenced at line numbers:
206+
207+
$$
208+
L^{(j)} = {l^{(j)}_1, l^{(j)}_2, ..., l^{(j)}_{n_j}} \quad \text{(sorted in ascending order)}
209+
$$
210+
211+
---
212+
213+
#### 3. Assign weights to each reference
214+
215+
Each reference line $l^{(j)}_i$ is assigned a weight $w^{(j)}_i$ depending on whether it is a simple read or an assignment:
216+
217+
- If the reference is **an assignment (update)**:
218+
$$
219+
w^{(j)}_i = \alpha \quad (\text{default: } \alpha = 2)
220+
$$
221+
222+
- If the reference is **a read-only access**:
223+
$$
224+
w^{(j)}_i = 1
225+
$$
226+
227+
---
228+
229+
#### 4. Calculate Variable Hard Usage for each variable
230+
231+
Let $l^{(j)}_\text{base} = l^{(j)}_1$, the first line where $v_j$ appears.
232+
233+
Then, the hard usage score for $v_j$ is calculated as:
234+
235+
$$
236+
H(v_j) = \sum_{i=1}^{n_j} w^{(j)}_i \cdot |l^{(j)}_i - l^{(j)}_\text{base}|
237+
$$
238+
239+
This measures how widely and intensely the variable is used, with updates having a stronger impact.
240+
241+
---
242+
243+
#### 5. Sum all variable scores to get the score for the scope
244+
245+
The total **Variable Hard Usage** for the scope $S$ is:
246+
247+
$$
248+
H(S) = \sum_{j=1}^{m} H(v_j) = \sum_{j=1}^{m} \sum_{i=1}^{n_j} w^{(j)}_i \cdot |l^{(j)}_i - l^{(j)}_\text{base}|
249+
$$
250+
251+
A larger value of $H(S)$ indicates that variables in the scope are heavily and broadly used, which may reduce code readability and maintainability.
201252

202253
### Example
203254

0 commit comments

Comments
 (0)