-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect number of distinct operators in Halstead metric #161
Comments
Hi @rwbogl, I'm very sorry for the long delay. Do you happen to still have the code for this? I have been fixing a lot of issues and I'd like to close these two as well. You are welcome to open a PR! |
https://www.geeksforgeeks.org/software-engineering-halsteads-software-metrics/ from Software Engineering | Halstead’s Software Metrics
int sort (int x[ ], int n) { def sort(X,n): Comparing the halstead´s numbers of C and Python codes for the same function the differences are very discrepant, they deserve a review. grateful for the attention. |
@eloifavero The code above is quite difficult to read. Also, I am not sure those two implementations can be compared because they are quite a lot different. If you post them with proper indentation and syntax highlighting I'll be happy to take a look. |
I'm curious about that, so I'm going to take the code from the source and try touching it up myself. int sort (int x[ ], int n)
{
int i, j, save, im1;
/*This function sorts array x in ascending order */
If (n< 2) return 1;
for (i=2; i< =n; i++)
{
im1=i-1;
for (j=1; j< =im1; j++)
if (x[i] < x[j])
{
Save = x[i];
x[i] = x[j];
x[j] = save;
}
}
return 0;
} def sort_translated(x, n):
if n < 2:
return 1
for i in range(2, n + 1):
im1 = i - 1
for j in range(1, im1 + 1):
if x[i] < x[j]:
save = x[i]
x[i] = x[j]
x[j] = save
return 0
def sort_more_idiomatic(x, n):
if n < 2:
return 1
for i in range(2, n + 1):
for j in range(1, i):
if x[i] < x[j]:
x[i], x[j] = x[j], x[i]
return 0 |
While trying to fix #160, I noticed that the Halstead visitor counts operands incorrectly. Essentially, it states that every expression that an operator is applied to is a distinct operator. For example, in the current master,
has two distinct operands. These are
x
andx + x
.The problem is that the operator visitors claim to know what operands they are being applied to. In
x + (x + x)
, the first+
claims to apply tox
and(x + x)
, and treats(x + x)
as an actual operand. I believe that Halstead only ever meant variables as operands, not arbitrary expressions containing them.I believe that this can be fixed by forcing every visitor method to ignore operands entirely and implementing a
visit_Name
method. I tried this in a quick experiment, and it fixes the above example. It also gives more reasonable results when combined with thevisit_Assignment
method requested in #160.The text was updated successfully, but these errors were encountered: