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)

enhancement

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) { >>... >>}
This is just coding style/best practices, right?
Yes, but this can be very easy detected/ corrected through static analysis.
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
(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.
(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.
Product: Core → Firefox Build System

Giving this more thought I'm not sure we actually need this.

Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.