You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parentheses
Go needs fewer parentheses than C and Java: control structures (if, for, switch) do not have parentheses in their syntax. Also, the operator precedence hierarchy is shorter and clearer, so
x<<8 + y<<16
means what the spacing implies, unlike in the other languages.
This is indeed intended behavior. Just like (5 * 2) has spaces around the *, but adding a + removes them ((5*2 + 2)) to provide visual grouping. Here the , has precedence, so the spaces are removed to provide visual grouping in the arguments.
It gets more useful in cases like ("test"+str1, "test"+str2), where you can clearly see there are two arguments.
In following code, both functions have argument
str
, and both functions are called with"test"+str1
, go-fmt should have same behavior handling them.But the first case, there will be spaces inserted around
+
, in second case, the spaces will be removed around+
.The text was updated successfully, but these errors were encountered: