Skip to content
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

[EC4] [Java] Rule "Avoid using global variables" discussion #51

Open
dedece35 opened this issue Jan 27, 2023 · 2 comments
Open

[EC4] [Java] Rule "Avoid using global variables" discussion #51

dedece35 opened this issue Jan 27, 2023 · 2 comments
Labels
🗃️ rule rule improvment or rule development or bug java __PRIO_MEDIUM__

Comments

@dedece35
Copy link
Member

dedece35 commented Jan 27, 2023

Is your feature request related to a problem? Please describe.
The java rule Avoid using global variables with id cnumr-java:D4 isn't really "good" for our society for different reasons :

  • java IDE generates automatically a global variable with serialID for classes implementing "Serializable" interface : we have a lot this kind of modification : please see capture varGlobale-1
  • it's a good practice in java language to have a common global variable representing a constant used in one or several classes : please see capture varGlobale-2
  • it's a good practice in java language to have a common global variable with pre-compiled regex Pattern to avoid compiling this pattern each time a local method is called. This rule is against native SaonrQube rule Regex patterns should not be created needlessly (id : java:S4248) : please see capture

varGlobale-3

please check also rule Avoid using Pattern.compile() in a non-static context. (id cnumr-java:S77) because it's quite against the rule Avoid using global variables (id cnumr-java:D4)

Describe the solution you'd like

  • for the moment, this rule is disabled in our SonarQube
  • check why this rule is relevant in our plugin

what is your point of view @glalloue, @jules-delecour-dav, @jhertout, @olegoaer, @mdubois81 ?

@dedece35 dedece35 added 🗃️ rule rule improvment or rule development or bug java labels Jan 27, 2023
@jhertout
Copy link
Contributor

I did not know the rule but I agree with you @dedece35. If this rule is not compliant with eco-development, we have to justify it by:

  • demonstrating its energy consumption
  • indicating the good practice

With that we can begin to discuss with team developers but else I think I that I should have deactivated the rule in the same situation.

@MP-Aubay
Copy link
Contributor

Hi @dedece35 ,

I totally agree with you concerning constant, I do not know why this rule have been merged without change, I was highlighting it in the PR: cnumr/ecoCode#93

In Java we could consider that this code could be bad practice:

public class HelloWorld {
    public static String myGlobalVariable;
}

But concerning memory consumption I do not know if this rule is pertinent in Java.

@dedece35 dedece35 changed the title Java Rule "Avoid using global variables" discussion [EC4] [Java] Rule "Avoid using global variables" discussion Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗃️ rule rule improvment or rule development or bug java __PRIO_MEDIUM__
Projects
None yet
Development

No branches or pull requests

3 participants