-
Notifications
You must be signed in to change notification settings - Fork 79
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
[EC53][JAVA] Rule to challenge - deprecation #240
Comments
EDIT: Maybe ignore this comment, I reversed List and Array in my reading of the list, so this comment is not really applicable. I understand the rule, but I see so many cases where array is not applicable. This feels like "hey, there are high-level objects, but low-level objects are more efficient." Java is high-level; if we must always go low-level, better do C or Rust. Here's some food for thought (and that's all it is because I can't make up my mind about this rule). Collections have several high-level specificities over array:
Replacing lists or collections with arrays will imply rewriting the logic included in the collection objects. I'd rather trust the authors of the JVM to have written those efficiently rather than having developers on every project reinventing the wheel. I won't go into the design rules that collections also allow, because we know that ecoCode will sometimes raise issues that will lead to having to compromise. The language provide objects for all those cases, Lists are only one of them. I agree we should use arrays when we can (we know the size, it won't change, etc.), but saying that all lists should be replaced with arrays is going one step further. To really be applicable, I think this rule should include some more parameters:
The most obvious case I can see for this rule is everytime we do a It's a really delicate rule, and I'm not sure of how it is applied now, how it should be applied or if it should be applied. Once again, if it throws warnings every time but can be fixed only 0.1% of the time, it will just be deactivated because it throws too many false positives. |
@cyChop Example private void myFunction(Class<?> cls) {
for(Field f: cls.getDeclaredFields()){// no compliant with EC53
//....
}
} private void myFunction(Class<?> cls) {
var myList = Arrays.asList(cls.getDeclaredFields()); // Duplicate Data in List = increase memory consumption
for(Field f: myList ){ // Compliant with EC53
//.....
}
} |
Oh sorry, I misread the rule and exchanged Lists and arrays. |
The issue haven't followed the repo migration, but in fact, this rule statement IS false. |
Hi @skerdudou, @diyfr, @cyChop, I agree with all of you that we can depreciate this rule because of following reasons :
I will create a new PR for to depreciate it and ask for a core team member review. |
Hello @dedece35, Seeing all the arguments you point, I agree that we should remove this rule. |
Hello! I have seen this resource with benchmarks: https://www-inf.telecom-sudparis.eu/COURS/cen/EfficaciteLogiciel/catalog.html#looping-over-an-array-or-an-arraylist They seem to qualify by saying that it depends on the use case, in some cases using a list is more efficient than an array (in joules), but that's not always the case. They are using JoularFX to get these benchmarks. I would also say that this rule needs to be deprecated. |
As confirmed with core-team, this rule will be deprecated soon because of implementation too simple (maybe come back later after proving it with measurements) |
Rule definition :
Using List instead of Arrays with Foreach save CPU cycles calculations and RAM consumption.
I have doubts about the relevance of this rule in Java
An array is lower level than a List, there is a good chance that the data traversal will be more efficient
Besides, I invite you to look at the source code of an ArrayList, where the data is stored in an... Array
1- See this sample benchmark test
2- When the object returned by a dependency is in Array format, it is expensive to transform it into a List in order to be able to browse it.
The text was updated successfully, but these errors were encountered: