Created
December 18, 2019 14:08
-
-
Save natanrolnik/26318bdb252049d20dfc25d1ffefc3df to your computer and use it in GitHub Desktop.
Examples of redundant else usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------ ⭣ Redundant Else ⭣ ------ | |
if someCondition { | |
return meh | |
} else { | |
let someValue = callSomeFunction() | |
return someValue | |
} | |
----------- ⭣ Fine ⭣ ----------- | |
if someCondition { | |
return meh | |
} | |
let someValue = callSomeFunction() | |
return someValue | |
----------- ⭣ Fine ⭣ ----------- | |
if someCondition { | |
doSomething() | |
} else { | |
doSomethingElse() | |
} | |
------ ⭣ Redundant Else ⭣ ------ | |
if someCondition { | |
return | |
} else { | |
callSomeFunction() | |
} | |
------ ⭣ Redundant Else ⭣ ------ | |
if someCondition { | |
return meh | |
} else if someOtherCondition { | |
let someValue = callSomeFunction() | |
return someValue | |
} else { | |
let someOtherValue = callSomeOtherFunction() | |
return someOtherValue | |
} | |
----------- ⭣ Fine ⭣ ----------- | |
if someCondition { | |
return meh | |
} | |
if someOtherCondition { | |
let someValue = callSomeFunction() | |
return someValue | |
} | |
let someOtherValue = callSomeOtherFunction() | |
return someOtherValue | |
------ ⭣ Redundant Else ⭣ ------ | |
for string in stringsArray { | |
if string.isEmpty { | |
continue | |
} else { | |
doSomething(with: string) | |
} | |
} | |
----------- ⭣ Fine ⭣ ----------- | |
for string in stringsArray { | |
if string.isEmpty { | |
continue | |
} | |
doSomething(with: string) | |
} | |
------ ⭣ Redundant Else ⭣ ------ | |
for string in stringsArray { | |
if string.isEmpty { | |
break | |
} else { | |
doSomething(with: string) | |
} | |
} | |
----------- ⭣ Fine ⭣ ----------- | |
for string in stringsArray { | |
if string.isEmpty { | |
break | |
} | |
doSomething(with: string) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment