Style guide: in or =

JuMP’ style guide states we should prefer in over = in for loops:
I was wondering why it is not the same for variables and constraints declaration as in the documentation we can find @variable(model, x[i=1:4; mod(i, 2)==0]) instead of @variable(model, x[i in 1:4; mod(i, 2)==0]). Is there a reason for choosing = in this case?
Thank you
Rémi Garcia

1 Like

Good question, I don’t think we’ve explicitly considered this, but I agree that it should be covered by the JuMP style guide. My initial response is that in (with required spaces before and after) is 4x as many characters as =. It’s common to have multiple indices like this for a variable, e.g., @variable(model, x[i=1:N, j=1:N, k=1:N]), so the effect of the extra characters is may be more significant than for regular for loops.

See also the discussion at

I understand your point, thanks!

I’ve always few constraints that have too many characters anyway. Hence I have to add breaks after the indices and a few characters are not a problem. Thanks for the link to the discussion, that was really interesting too.