From deb69201e348a46a8b89575d85d9566bcebf193e Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Thu, 16 Aug 2018 20:16:48 +0200 Subject: [PATCH] Added "Avoid double negation" section --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 1a12402..173663f 100644 --- a/README.md +++ b/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 }`