-
Notifications
You must be signed in to change notification settings - Fork 71
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
for = vs for in normalization #34
Comments
I'm in favour of this. Additionally this is a best practice for the prevalent style guides: |
Good idea. |
I'm "some people" ;) I've found |
It's more difficult to type ∈. Also, ∈ is rarely found in other languages. |
about why use `i = 1:nfields(data)` see: domluna/JuliaFormatter.jl#34
I am "some people" also. In fact, some nonofficial guide has suggested not to use |
I'm for always using |
Yes, you're more strict than Julia's style guide, that has this line: for i = firstindex(a):lastindex(a) uur guide and Karpinski's reasoning here: domluna/JuliaFormatter.jl#34 I'm not sure I agree, but it's not good if the formatter generates style incompatible with guide(s). Your guide was updated in 2018 to reflect JuMP's but I at least didn't locate wording on this (yet) there.
Going to chime in on this dead issue that
Is incorrect. JuMP's rule is to always prefer
You could (and I will) argume that |
https://github.com/jrevels/YASGuide also recommends using |
I also opt for |
Is there a way to choose different syntax guide? like this one. I also opt for in over = in all circumstances... |
No, there are currently no formatting options. |
The rule of thumb that I use for
for
loops is that if the thing you're iterating over is a literal range then you use=
whereas if it's anything else (e.g. an object) then I usein
. So, for example, these would be "correct":These, on the other hand would be "incorrect":
Part of the reasoning is that
for i = 1:n
looks like it assignsi
to 1, then 2, then ...n
— at least in common mathematical / pseudocode notation, whereasfor i = itr
looks like it assignsi = itr
which is not what it does. So one could argue "why use/allowfor i = 1:n
at all? Why not just usein
uniformly and writefor i in 1:n
andfor i in itr
? Some people surely would prefer this. However, this superficial syntax difference can help catch a common error, which is writingfor i = n
when you meant to writefor i = 1:n
. If we requirein
there then the programmer will notice thatfor i in n
is not what they meant to write and catch the bug.So I would propose normalizing
for =
versusfor in
based on this rule. Thoughts?The text was updated successfully, but these errors were encountered: