mirror of
https://github.com/wnagrodzki/iOSProgrammingGuidelines.git
synced 2025-05-03 17:41:33 +02:00
Added "Avoid double negation" section
This commit is contained in:
parent
bd07134e22
commit
deb69201e3
1 changed files with 30 additions and 0 deletions
30
README.md
30
README.md
|
@ -82,3 +82,33 @@ Gather IBOutlets in one group above all the other properties and keep them priva
|
|||
```
|
||||
|
||||
> Outlets are implementation detail and should be kept private. Gathering them in one grup above all the other properties is old convention.
|
||||
|
||||
### Avoid double negation
|
||||
|
||||
Don't not avoid double negation.
|
||||
```swift
|
||||
if !unavailable {
|
||||
//...
|
||||
}
|
||||
```
|
||||
> This is to avoid confusion.
|
||||
|
||||
Use "positive" names for variables and properties.
|
||||
|
||||
```swift
|
||||
if available {
|
||||
//...
|
||||
}
|
||||
```
|
||||
```swift
|
||||
return available ? operationWhenAvailable() : nil
|
||||
```
|
||||
> This is to decrease mental tax often caused by "negative" properties. It will also help keeping "main" application flow on the left hand side of colon when conditional operator `?:` is used.
|
||||
|
||||
Do not use negative conditions with guard.
|
||||
```swift
|
||||
guard !array.isEmpty else { return }
|
||||
```
|
||||
|
||||
> This is to restrain overusing of `guard` statement where `if` would suffice.
|
||||
> `if array.isEmpty { return }`
|
||||
|
|
Loading…
Add table
Reference in a new issue