-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize all =
to in
in for loops
#70
Conversation
How do you propose catching the common issue where people write |
Looking through more cases, Base + stdlib Julia code is actually remarkably consistent about following the rule that is currently implemented. |
Do you mean from a correctness standpoint? Or a stylistic standpoint? julia> function foo(n)
for i in n
println(i)
end
end
foo (generic function with 1 method)
julia> function bar(n)
for i = n
println(i)
end
end
bar (generic function with 1 method)
julia> foo(5)
5
julia> bar(5)
5 |
Yes, I mean from a correctness standpoint. If the convention is that one uses |
Okay, fair point. I see the benefit, and I've lost some zeal for this change. To summarize: the trade off is therefore between people making the mistake I'm not sure which I prefer... I guess the root issue is that numbers are iterable. (Slightly off-topic, but was there a reason for this?) |
FWIW, given a good auto-formatter, the default workflow for me would be "auto format and forget", which means that if I wrote "for i = n", it would just get corrected without raising a flag to "for i in n" regardless of if I intended to write a literal range. In this case the information in the "parity bit" is quickly lost. It would be another question if the proposal was to make |
Agree, it's probably not very effective just as part of the standard formatting. To be effective, it needs to also be something that linters can warn about, but for that to be possible, it needs to be standard. Even in situation where one blindly runs the formatter and later goes bug hunting, at least the fact that it's
|
I think generally At first I was in the use Thoughts on allowing use of either for i = 1:10
end
for i in 1:10
end But this would be incorrect: for i = I
end I believe this still captures the initiative for #34 (I might be wrong) and keeps the |
@domluna I would prefer that you chose exactly one of the two options and make it a rule. We shouldn't carve out exceptions for special interest groups :) |
Oh man, "with great power comes great responsibility" a wise man once said. We're gonna stick to the current implementation then. @odow I appreciate the effort ❤️ |
Since #34 was closed, there has been a steady stream of people disagreeing. I get that it is a contentious issue with no settled style in the community, but this simplifies the rule:
for i in iter
except ititer
is a literal range, then usefor i = 1:n
.to
for i in iter
.Revises #35. Re-closes the already closed issue: #34