squid:S109 - Magic Numbers - ignore 2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

squid:S109 - Magic Numbers - ignore 2

Alix LOURME

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.

Reply | Threaded
Open this post in threaded view
|

Re: squid:S109 - Magic Numbers - ignore 2

Michael Gumowski
Hello Alix,

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 
We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.


Reply | Threaded
Open this post in threaded view
|

Re: squid:S109 - Magic Numbers - ignore 2

Timothy McNally
http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Accepted_limited_use_of_magic_numbers

It is useful in modulo operations for determining every other of something by determining even or odd.

On Wed, May 13, 2015 at 9:05 AM, Michael Gumowski <[hidden email]> wrote:
Hello Alix,

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 
We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.


Reply | Threaded
Open this post in threaded view
|

RE: squid:S109 - Magic Numbers - ignore 2

Alix LOURME

I Michael,

 

I haven't better arguments that Timothy's link URL.

 

In addition of conceptual reason, I see an operational reason: when you migrate all your historical checkstyle/pmd rules to squid (better, reduce parsing ...), this is a dead-end.

This rule has an interest but could be a (little) constraint for some developers => increase strictness (compared to historical config) could reduce the acceptance.

 

On the substance, it's only interpretation or choice ... because if I do "my punctilious", RSPEC-109 refers to AvoidLiteralsInIfCondition and MagicNumber, but PMD doesn’t accept “1” and S109 yes ;-).

 

Best regards.

De : Timothy McNally [mailto:[hidden email]]
Envoyé : mercredi 13 mai 2015 18:27
À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Accepted_limited_use_of_magic_numbers

 

It is useful in modulo operations for determining every other of something by determining even or odd.

 

On Wed, May 13, 2015 at 9:05 AM, Michael Gumowski <[hidden email]> wrote:

Hello Alix,

 

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 

We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

 

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

 

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.

 

Reply | Threaded
Open this post in threaded view
|

Re: squid:S109 - Magic Numbers - ignore 2

Michael Gumowski
Hey guys,

Thanks Timothy and Alix for providing your feedback. I can't really fight the reasons of not having 2 in the list... As I obviously totally forgot about using it in modulo and even/odd calculation. :')
To summarize the situation, at the moment the 3 rules we are speaking about accept by default the following numbers:

-  Java plugin S109: -1, 0, 1
- CheckStyle MagicNumber: -1, 0, 1, 2
- PMD AvoidLiteralsInIfCondition: -1, 0

Obviously, we are not going to be able to map exactly the PMD and checkstyle rules in S109 without having conflicts (adding 2 will "decrease" strictness regarding PMD's implementation).
I hate to admit it but we may need to add a parameter to set accepted magic numbers... with default value being -1, 0, 1.

Would you prefer that solution?

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

On 18 May 2015 at 10:33, ALIX LOURME <[hidden email]> wrote:

I Michael,

 

I haven't better arguments that Timothy's link URL.

 

In addition of conceptual reason, I see an operational reason: when you migrate all your historical checkstyle/pmd rules to squid (better, reduce parsing ...), this is a dead-end.

This rule has an interest but could be a (little) constraint for some developers => increase strictness (compared to historical config) could reduce the acceptance.

 

On the substance, it's only interpretation or choice ... because if I do "my punctilious", RSPEC-109 refers to AvoidLiteralsInIfCondition and MagicNumber, but PMD doesn’t accept “1” and S109 yes ;-).

 

Best regards.

De : Timothy McNally [mailto:[hidden email]]
Envoyé : mercredi 13 mai 2015 18:27
À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Accepted_limited_use_of_magic_numbers

 

It is useful in modulo operations for determining every other of something by determining even or odd.

 

On Wed, May 13, 2015 at 9:05 AM, Michael Gumowski <[hidden email]> wrote:

Hello Alix,

 

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 

We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

 

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

 

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.

 


Reply | Threaded
Open this post in threaded view
|

RE: squid:S109 - Magic Numbers - ignore 2

Alix LOURME

Hi,

 

The parameter with this default value is OK for me. Extend this rule with "-1,0,1,2" configuration for historic mapping is acceptable ;-).

If feature could be planned in the two/three next month java plugin roadmap (compatible with v4.5.x LTS), will be perfect.

 

Many thanks.

Best regards.

De : Michael Gumowski [mailto:[hidden email]]
Envoyé : lundi 18 mai 2015 10:59
À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

Hey guys,

 

Thanks Timothy and Alix for providing your feedback. I can't really fight the reasons of not having 2 in the list... As I obviously totally forgot about using it in modulo and even/odd calculation. :')

To summarize the situation, at the moment the 3 rules we are speaking about accept by default the following numbers:

 

-  Java plugin S109: -1, 0, 1

- CheckStyle MagicNumber: -1, 0, 1, 2

- PMD AvoidLiteralsInIfCondition: -1, 0

 

Obviously, we are not going to be able to map exactly the PMD and checkstyle rules in S109 without having conflicts (adding 2 will "decrease" strictness regarding PMD's implementation).

I hate to admit it but we may need to add a parameter to set accepted magic numbers... with default value being -1, 0, 1.

 

Would you prefer that solution?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 18 May 2015 at 10:33, ALIX LOURME <[hidden email]> wrote:

I Michael,

 

I haven't better arguments that Timothy's link URL.

 

In addition of conceptual reason, I see an operational reason: when you migrate all your historical checkstyle/pmd rules to squid (better, reduce parsing ...), this is a dead-end.

This rule has an interest but could be a (little) constraint for some developers => increase strictness (compared to historical config) could reduce the acceptance.

 

On the substance, it's only interpretation or choice ... because if I do "my punctilious", RSPEC-109 refers to AvoidLiteralsInIfCondition and MagicNumber, but PMD doesn’t accept “1” and S109 yes ;-).

 

Best regards.

De : Timothy McNally [mailto:[hidden email]]
Envoyé : mercredi 13 mai 2015 18:27
À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Accepted_limited_use_of_magic_numbers

 

It is useful in modulo operations for determining every other of something by determining even or odd.

 

On Wed, May 13, 2015 at 9:05 AM, Michael Gumowski <[hidden email]> wrote:

Hello Alix,

 

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 

We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

 

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

 

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.

 

 

Reply | Threaded
Open this post in threaded view
|

Re: squid:S109 - Magic Numbers - ignore 2

Fabrice Daugan
Hi,
For PMD and Checkstyle, there is a way to configure exception. It would be nice to have this feature too for the SonarQube rule. The default value would be "-1, 0, 1" as currently.

Regards,
Fabrice.

On Mon, May 18, 2015 at 11:20 AM, ALIX LOURME <[hidden email]> wrote:

Hi,

 

The parameter with this default value is OK for me. Extend this rule with "-1,0,1,2" configuration for historic mapping is acceptable ;-).

If feature could be planned in the two/three next month java plugin roadmap (compatible with v4.5.x LTS), will be perfect.

 

Many thanks.

Best regards.

De : Michael Gumowski [mailto:[hidden email]]
Envoyé : lundi 18 mai 2015 10:59


À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

Hey guys,

 

Thanks Timothy and Alix for providing your feedback. I can't really fight the reasons of not having 2 in the list... As I obviously totally forgot about using it in modulo and even/odd calculation. :')

To summarize the situation, at the moment the 3 rules we are speaking about accept by default the following numbers:

 

-  Java plugin S109: -1, 0, 1

- CheckStyle MagicNumber: -1, 0, 1, 2

- PMD AvoidLiteralsInIfCondition: -1, 0

 

Obviously, we are not going to be able to map exactly the PMD and checkstyle rules in S109 without having conflicts (adding 2 will "decrease" strictness regarding PMD's implementation).

I hate to admit it but we may need to add a parameter to set accepted magic numbers... with default value being -1, 0, 1.

 

Would you prefer that solution?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 18 May 2015 at 10:33, ALIX LOURME <[hidden email]> wrote:

I Michael,

 

I haven't better arguments that Timothy's link URL.

 

In addition of conceptual reason, I see an operational reason: when you migrate all your historical checkstyle/pmd rules to squid (better, reduce parsing ...), this is a dead-end.

This rule has an interest but could be a (little) constraint for some developers => increase strictness (compared to historical config) could reduce the acceptance.

 

On the substance, it's only interpretation or choice ... because if I do "my punctilious", RSPEC-109 refers to AvoidLiteralsInIfCondition and MagicNumber, but PMD doesn’t accept “1” and S109 yes ;-).

 

Best regards.

De : Timothy McNally [mailto:[hidden email]]
Envoyé : mercredi 13 mai 2015 18:27
À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Accepted_limited_use_of_magic_numbers

 

It is useful in modulo operations for determining every other of something by determining even or odd.

 

On Wed, May 13, 2015 at 9:05 AM, Michael Gumowski <[hidden email]> wrote:

Hello Alix,

 

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 

We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

 

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

 

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.

 

 




--
Fabrice Daugan
Reply | Threaded
Open this post in threaded view
|

Re: squid:S109 - Magic Numbers - ignore 2

Michael Gumowski
Hey all,

I created the following ticket to handle the addition of the parameter: http://jira.codehaus.org/browse/SONARJAVA-1079

Regards,

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

On 19 May 2015 at 13:41, Fabrice Daugan <[hidden email]> wrote:
Hi,
For PMD and Checkstyle, there is a way to configure exception. It would be nice to have this feature too for the SonarQube rule. The default value would be "-1, 0, 1" as currently.

Regards,
Fabrice.

On Mon, May 18, 2015 at 11:20 AM, ALIX LOURME <[hidden email]> wrote:

Hi,

 

The parameter with this default value is OK for me. Extend this rule with "-1,0,1,2" configuration for historic mapping is acceptable ;-).

If feature could be planned in the two/three next month java plugin roadmap (compatible with v4.5.x LTS), will be perfect.

 

Many thanks.

Best regards.

De : Michael Gumowski [mailto:[hidden email]]
Envoyé : lundi 18 mai 2015 10:59


À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

Hey guys,

 

Thanks Timothy and Alix for providing your feedback. I can't really fight the reasons of not having 2 in the list... As I obviously totally forgot about using it in modulo and even/odd calculation. :')

To summarize the situation, at the moment the 3 rules we are speaking about accept by default the following numbers:

 

-  Java plugin S109: -1, 0, 1

- CheckStyle MagicNumber: -1, 0, 1, 2

- PMD AvoidLiteralsInIfCondition: -1, 0

 

Obviously, we are not going to be able to map exactly the PMD and checkstyle rules in S109 without having conflicts (adding 2 will "decrease" strictness regarding PMD's implementation).

I hate to admit it but we may need to add a parameter to set accepted magic numbers... with default value being -1, 0, 1.

 

Would you prefer that solution?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 18 May 2015 at 10:33, ALIX LOURME <[hidden email]> wrote:

I Michael,

 

I haven't better arguments that Timothy's link URL.

 

In addition of conceptual reason, I see an operational reason: when you migrate all your historical checkstyle/pmd rules to squid (better, reduce parsing ...), this is a dead-end.

This rule has an interest but could be a (little) constraint for some developers => increase strictness (compared to historical config) could reduce the acceptance.

 

On the substance, it's only interpretation or choice ... because if I do "my punctilious", RSPEC-109 refers to AvoidLiteralsInIfCondition and MagicNumber, but PMD doesn’t accept “1” and S109 yes ;-).

 

Best regards.

De : Timothy McNally [mailto:[hidden email]]
Envoyé : mercredi 13 mai 2015 18:27
À : [hidden email]
Objet : Re: [sonar-user] squid:S109 - Magic Numbers - ignore 2

 

http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Accepted_limited_use_of_magic_numbers

 

It is useful in modulo operations for determining every other of something by determining even or odd.

 

On Wed, May 13, 2015 at 9:05 AM, Michael Gumowski <[hidden email]> wrote:

Hello Alix,

 

I'm sorry, but except if you provide a very good reason, we probably won't change the rule's behavior and we will keep considering 2 as a magic number for the time being. 

We won't add any parameter to the rule neither, as we try to limit the rule parameters as much as possible.

 

On this point we will indeed slightly differ from the checkstyle implementation, by being a little bit more strict.

 

I'm however wondering... Why 2 should be excluded, is it more interesting than 3 or 10? if it is generating too much noise, then in what kind of situations?

 

Regards,


Michael GUMOWSKI | SonarSource

Software Developer @ Language Team
http://sonarsource.com

 

On 13 May 2015 at 16:50, ALIX LOURME <[hidden email]> wrote:

Hi,

 

Historically, checkstyle doesn't consider '2' as a magic number.

checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck is depreciate for squid:S109, but ‘2’ is a magic number in this squid rule.

 

=> Could ‘2’ not considered as magic number in this rule; to have the same as checkstyle behavior … or could be configurable as rule parameter?

 

Thanks in advance.

Best regards.

Alix.

 

 




--
Fabrice Daugan