Closed StefanKarpinski closed 5 years ago
I'm in favour of this.
Additionally this is a best practice for the prevalent style guides:
Good idea.
why use/allow for i = 1:n at all? Why not just use in uniformly and write for i in 1:n and for i in itr? Some people surely would prefer this.
I'm "some people" ;) I've found for =
difficult to read, so I always use for in
. I would prefer for ∈
instead of for =
if a difference should be made.
It's more difficult to type ∈. Also, ∈ is rarely found in other languages.
I am "some people" also. In fact, some nonofficial guide has suggested not to use for ... = ...
.
I'm for always using in
.
Going to chime in on this dead issue that
Additionally this is a best practice for the prevalent style guides:
Is incorrect. JuMP's rule is to always prefer in
over =
.
Part of the reasoning is that for i = 1:n looks like it assigns i to 1, then 2, then ... n — at least in common mathematical / pseudocode notation, whereas for i = itr looks like it assigns i = itr which is not what it does.
You could (and I will) argume that i = 1:n
looks like it assigns i
to the iterable 1:n
.
https://github.com/jrevels/YASGuide also recommends using in
over =
. @domluna , is it difficult to update the code to use in
instead of =
?
I also opt for in
over =
in all circumstances although my visual cortex interprets them the same anyways. I love ∈
because it's cool but often it's just too much to type and so in
wins.
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?