Require spaces around binary ops
Posted: Wed Jul 03, 2013 12:45 pm
Actually, spaces are already required around named binary ops such as "and" and "or". But we also have these binary ops:
arithmetic: + - * / ...
assignment: = += -= ...
bitwise: & | ...
coalesce: ?
I mentioned on another thread:
For which there were two positive responses. Although one was based on the idea of having dashed identifiers and I can't honestly say I was planning that. What I am planning if we introduced this constraint is two new convenience operators:
Both of those operators are not currently possible in Cobra because they are ambiguous with multiplication and coalesce, respectively.
Another advantage to requiring spaces around binary ops is a more uniform coding style between code bases. Also, a more consistent coding style within a given code base. Also I wouldn't have to edit patches as much. I often get:
...in the same patch.
Playing devil's advocate, disadvantages include:
-- Impact on legacy code.
-- New users of Cobra may be turned off by what they perceive as pickiness.
-- The above new operators may still look ambiguous (although I'm skeptical of this point).
Your thoughts?
arithmetic: + - * / ...
assignment: = += -= ...
bitwise: & | ...
coalesce: ?
I mentioned on another thread:
Sometimes I think programming languages would be better off requiring a space around binary operators such as comparisons, arithmetic, etc.
For which there were two positive responses. Although one was based on the idea of having dashed identifiers and I can't honestly say I was planning that. What I am planning if we introduced this constraint is two new convenience operators:
# Spread operator
items*.clear
# equivalent to:
for item in items, item.clear
# another example
names = customers*.name
# -->
names = for c in customers get c.name
# Safe navigation operator - avoid null ref exceptions
companyName = user?.company?.name
Both of those operators are not currently possible in Cobra because they are ambiguous with multiplication and coalesce, respectively.
Another advantage to requiring spaces around binary ops is a more uniform coding style between code bases. Also, a more consistent coding style within a given code base. Also I wouldn't have to edit patches as much. I often get:
a= 1
b =2
c = 3
Playing devil's advocate, disadvantages include:
-- Impact on legacy code.
-- New users of Cobra may be turned off by what they perceive as pickiness.
-- The above new operators may still look ambiguous (although I'm skeptical of this point).
Your thoughts?