-
Notifications
You must be signed in to change notification settings - Fork 81
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
Questions and analyze #53
Comments
@yegor256 please, pay attention to this issue |
I've created pull request #54 for show a bug with generic methods. Pull request relates only for CAMC metric, but if we are going to fix it I will add test for all metrics. Let's see what was happened in tests for class
But result was 0.3333. It was happend because we counted
I will fix that if we will decide that is wrong behaviour or you can just close pull request without merging and without any fixes. |
@sergey-karazhenets for CAMC:
Yes, totally agree.
I think we should treat
I think we should not consider constructors as methods. Let's try to find some papers that confirm that. Again, let's create a class that will fetch all methods from a class. Let's use it everywhere in all metrics, to make this decision universal for the entire product.
I would say we pay attention only to public methods.
I agree with the fix introduced. |
@sergey-karazhenets once again, let's not forget that there are many metrics. Let's try to make all changes apply to all metrics. Try to introduce new classes, instead of making changes to specific metrics. |
@sergey-karazhenets can you please split this ticket to a few separate tickets? Now it's difficult to track the progress. |
I have analyzed some implemented metrics and also think about the following questions during implementation metrics where we counting methods of a class and types of method parameters or return types. Next questions relate to all metrics and I think it should be clarified for all who want to implement some new metric. To be easy it to understand what I want to say let's look to CAMC metric implementation. We can take any metric, but CAMC has easy description and formula.
See this one paper Class Cohesion Metrics for Software Engineering: A Critical Review, PDF, Table 2. Interface-based metrics. CAMC metric is described as:
1. Letter
l
in formula is a number of distinct parameter types across all methods in a class. For example, if class has the next methodsthen
l
should be equals to 1 because two methods have the same parameter typeString
. But for committed to repository implementationl
will be equals to 2. It happens because our implementation counts not only parameter types of method but also it counts return types of method. For code above it countsint
andString
. I think our implementation contradicts to definition in the paper, we should count only parameter types of method.One more evidence for that: if we should count both parameter types of method and return types then it clearly is wrote in the paper. See description for MMAC metric. Paper clearly tells us that
i
is can be a parameter type of method or return type. In the description of CAMC metricl
is defined only as count of parameter types.So, am I right that we should count only parameter types of method for
l
?2. For example class has the next method:
Let see the point 1 above, for CAMC metric we should calculate value
l
as a number of distinct parameter types for method. Our implmentation countsl
as 2 because method has two distinct types:int
andjava.lang.Integer
. Also we can see it in a bytecode of method:For compiler
int
andjava.lang.Integer
it is two different types, but for human it is one type for integer values.So, should we consider simple types and theirs analogous boxed types as the same types or consider them as different types (like compiler does)?
3. Letter
k
in CAMC formula is a number of all methods in a class.So, is it correct that we consider constructors as methods?
Should we consider only public methods or consider all methods (public, private, protected, package-private)? I think we should consider all methods, but what do you think?
If class inherits from another class then should we consider methods from parent class? I think we shouldn't, but what do you think?
4. Also interesting bug in counting of all methods in a class when class overrides one or more generic methods from parent. Let's see the next code:
We have generic interface
GenericIncrementor1
and its implementation presented by classOverrideGenericMethodFromInterface
. Visually we see only one method inOverrideGenericMethodFromInterface
class, it ispublic Integer inc() { }
. And when we count methods for some metric we expect that Javassist or ASM returns us only one method. But it doesn't. It returns two methods. Why does it happen? Let's see to the bytecode:In the bytecode two methods is presented:
public inc()Ljava/lang/Integer;
andpublic synthetic bridge inc()Ljava/lang/Object;
. And according that Javassist or ASM works properly when returning two methods, because bytecode contains two methods. Compiler always generates one more method on each implementation of generic method in a class. And it impacts all our metrics. To avoid incorrect counting of all methods in a classs we should excludesynthetic
methods.Let's discuss all points/questions and I will fix them if it will be needed.
The text was updated successfully, but these errors were encountered: