Skip to content

Commit 7ba538f

Browse files
committed
Update README.md
1 parent 38e6e0e commit 7ba538f

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ func outputDetailsForPath(path: String, fileSize: Int, extension: String,
113113

114114

115115
### 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
116+
Rationale: Operators are usually special symbols(+-/) and when they dont have enough whitespaces they make code much harder to read. The white spaces rule is very universal and simple to remember:
117+
#####Binary operators: One space before and one space after
118+
#####Unary operators: Just once space either before or after the operator
121119
Examples:
122120
**Good:**
123121
```swift
@@ -177,3 +175,39 @@ if(condition){
177175
sleep()
178176
}
179177
```
178+
179+
http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS
180+
181+
```swift
182+
if condition {
183+
// do stuff
184+
} else {
185+
// do other stuff
186+
}
187+
```
188+
189+
190+
####Return early
191+
192+
If you have to meet certain criteria to continue execution, return early.
193+
194+
**Good:**
195+
```swift
196+
guard condition else { return error }
197+
```
198+
199+
**Bad:**
200+
```swift
201+
if (condition) {
202+
// condition satisfied code
203+
} else {
204+
if (anothertest) {
205+
foo()
206+
} else {
207+
return error
208+
}
209+
}
210+
```
211+
212+
When returning early prefer ''guard'' over ''if''.
213+

0 commit comments

Comments
 (0)