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
### Whitespaces around binary and unary operators.
116
+
Rationale: Operators are usually special symbols(+-/) and when they dont have enough whitespaces they make code much harder to read. The rule is rather universal and holds for all operators:
117
+
####Binary operators
118
+
One space before and one space after
119
+
###Unary operators
120
+
Just once space either before or after the operator
121
+
Examples:
122
+
**Good:**
123
+
```swift
124
+
func<|< <A>(lhs: A, rhs: A) -> A
125
+
```
126
+
**Bad:**
127
+
```swift
128
+
func<|<<A>(lhs: A, rhs: A) -> A
129
+
```
130
+
The same holds for arithmetic operators
131
+
**Good:**
132
+
```swift
133
+
let size = viewWidth -2* FIRST_CONSTANT - secondConstant - totalConstant
134
+
```
135
+
**Bad:**
136
+
```swift
137
+
let size=viewWidth-2*FIRST_CONSTANT-secondConstant-totalConstant
138
+
```
139
+
140
+
The same rule for the return type of functions:
141
+
142
+
**Good:**
143
+
```swift
144
+
funcsizeOfObject() ->Float {
145
+
}
146
+
```
147
+
**Bad:**
148
+
```swift
149
+
funcsizeOfObject()->Float{
150
+
}
151
+
```
152
+
153
+
The same rule holds for the Swift ternary operator (from Apple's Swift guide)
0 commit comments