Open golszewski86 opened 5 years ago
@golszewski86/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!
@golszewski86 Yeah, you are right. And in most cases many devs hack it by using ++idx and --idx.
@yegor256 Can this rule go away? Or is there a justification for it?
@krzyk a possible reason is to avoid this mistake:
int x = 1;
int y = x++;
System.out.println(x); // prints 2
System.out.println(y); // prints 1
Someone may mistakenly expect y == 2.
I'm sorry @llorllale but this reason doesn't make sense to me. I understand some people may not know how do the post-increment and pre-increment work, but this is not the reason to disable these constructions for everyone.
@krzyk just use ++i
and that's it. I don't see why the rule should go away.
@yegor256 yeah, but both postfix and prefix increment /decrement in my opinion is equally bad. So why discourage just one? (or at all?). I think we should either prohibit both or none.
@krzyk why do you think the preincrement is bad?
@llorllale it 8s in the same group as postincrement, so if we discourage one, we should do the same with the other.
Personally I don't have anything against either one if the result of the expression is not used.
@krzyk I don't think that pre-increment is bad. Post-increment is bad for a very specific reason -- it returns the value before the increment, which makes code less readable. Pre-increment is side-effect free, so to speak. So, I vote for ++i
but against i++
.
Post-increment is bad for a very specific reason -- it returns the value before the increment, which makes code less readable
That's just an opinion @yegor256, maybe it's less readable for you but not for everyone. I'd expect code quality rules to be based on generally acknowledged rules, not personal opinions about readability.
@golszewski86 rules in qulice are generally decided by generally acknowledged rules but in some cases our PO (Yegor) decides about them in more personal way, look at http://yegor256.com/ for explanations why some of the rules are configured the way they are. You can see some good arguments against i++
from at least two people.
@krzyk yep there are two arguments:
So there's actually only one argument, and it's not a good one.
Please see qulice-checkstyle/src/main/resources/com/qulice/checkstyle/checks.xml
It prohibits usage of the post increment and decrement operators(like idx++ or idx--), however there is no justification for it. I wasn't able to find one on the intenet except people saying it's more efficient in C/C++.
Could you please provide justification, and maybe include it in the checks.xml file?