Closed
Bug 1372209
Opened 8 years ago
Closed 6 years ago
Analysis to reject the comparison of variables with constants situated on the left side of the expression
Categories
(Developer Infrastructure :: Source Code Analysis, enhancement, P5)
Developer Infrastructure
Source Code Analysis
Tracking
(Not tracked)
RESOLVED
WORKSFORME
People
(Reporter: andi, Assigned: andi)
Details
We shouldn't allow in our code comparisons where the constant is situated on the left side of the binary operation, like:
>>if (MAX_NUMBER > m_LocalNumber) {
>>...
>>}
this should be written as:
>>if (m_LocalNumber<MAX_NUMBER) {
>>...
>>}
Comment 1•8 years ago
|
||
This is just coding style/best practices, right?
| Assignee | ||
Comment 2•8 years ago
|
||
Yes, but this can be very easy detected/ corrected through static analysis.
Comment 3•8 years ago
|
||
I don't think this is very high priority. It's going to require lots of changes to the codebase, and make working on our code more annoying, because even more technically correct code will fail only when run on try.
I'm inclined to not implement this, especially before we get a good story for running the analysis locally (such as bug 1328454), but I'll mark it as P5 for now.
Priority: -- → P5
Comment 4•8 years ago
|
||
(In reply to Andi-Bogdan Postelnicu [:andi] from comment #0)
> We shouldn't allow in our code comparisons where the constant is situated on
> the left side of the binary operation, like:
>
> >>if (MAX_NUMBER > m_LocalNumber) {
> >>...
> >>}
>
> this should be written as:
>
> >>if (m_LocalNumber<MAX_NUMBER) {
> >>...
> >>}
Forgive me for being dense... but why does this matter? What improvement does this bring? I can't see it being a compiler issue: compilers should be smart enough to reorder the arguments for the most optimal assembly code without much trouble, especially for primitives.
| Assignee | ||
Comment 5•8 years ago
|
||
(In reply to Alex Vincent [:WeirdAl] from comment #4)
> (In reply to Andi-Bogdan Postelnicu [:andi] from comment #0)
> > We shouldn't allow in our code comparisons where the constant is situated on
> > the left side of the binary operation, like:
> >
> > >>if (MAX_NUMBER > m_LocalNumber) {
> > >>...
> > >>}
> >
> > this should be written as:
> >
> > >>if (m_LocalNumber<MAX_NUMBER) {
> > >>...
> > >>}
>
> Forgive me for being dense... but why does this matter? What improvement
> does this bring? I can't see it being a compiler issue: compilers should
> be smart enough to reorder the arguments for the most optimal assembly code
> without much trouble, especially for primitives.
Performance wise, you are right, this checker should be more looked up as an enforcer for a good coding style.
Updated•7 years ago
|
Product: Core → Firefox Build System
| Assignee | ||
Comment 6•6 years ago
|
||
Giving this more thought I'm not sure we actually need this.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
Updated•3 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•