johnmyleswhite / Style.jl

Style guideline for Julia
74 stars 12 forks source link

Clarification on #9? #4

Closed sbromberger closed 9 years ago

sbromberger commented 9 years ago

(9) Always insert a single space before and after an operator, except for the ^ and : operators, which never have spaces around them

What about statements of the format

a = (x > 0)? foo : bar ? Should we have no spaces around that colon? (Arguably, the colon here is not functioning as an operator, but that's a pretty obscure difference.)

johnmyleswhite commented 9 years ago

I don't think it's that obscure a difference. The AST clearly distinguishes these two constructs and would never have trouble implementing different logic.

It's effectively the same thing as saying that the second + of the ++ operator isn't equivalent to the + operator. The ternary operator may be separated by other cruft, but it's still a single operator and not equivalent to the colon operator.

sbromberger commented 9 years ago

so we're distinguishing between the ": operator" and the "ternary operator", both of which are represented by a single colon?

johnmyleswhite commented 9 years ago

Nope, the ternary operator is a three-part operator that looks like a ? b : c.

sbromberger commented 9 years ago

Got it. Thanks for the explanation.