I need help to understand the following codes. Why does it print "yes" even if !test is equal to true. Thanks
var test: Bool = false
if !test {
print("yes")
}
if !test == true {
print("oky")
}
print(!test)
Console:
yes
oky
true
I want to add that there are developers for whom the negative logic is hard to read. Below are some examples of such logical expressions.
examples of logic that takes time to process::
possible solutions are:
There is a great article that threats the subject in-depth:
Don’t ever not avoid negative logic
If you want to be nice to people with a challenged relationship with boolean logic, try to avoid negative formulations and negations.