Closed Paul-Wassermann-CA closed 4 months ago
Agreed, I got bitten by this non-issue yesterday on a work project when activating the eco rules.
Is it a failed port of an equivalent rule in another language ?
I believe this rule should be simply removed.
Hi, thank you for your demonstration. What do you think about this issue @jhertout ? are you ok to remove this rule for python ?
I'm ok to check on other language.
Hello @dedece35. I perform some tests as described in this issue to verify and indeed I think we can remove this rule for Python. May be we can check this rule in other languages too and maybe there are differences between old traditionnal for loop (for int i = 0 ; i < 10 ; i++) and foreach loop in other language where the 2 kinds of loops are possible.
Rule EC69 is irrelevant for Python. The rule seems to imply that calling a function in a for statement results in calling this function multiple times, which is not true.
The two following syntaxes are strictly equivalent regarding the number of calls to the
range
builtin function :A simple way to prove see this is using a counter :
This prints
2
since the function is called only twice.Therefore, I think the rule should be dropped since it's confusing and doesn't make much sense from an eco-design perspective, at least for Python, but it should be investigated for other languages too.