I'm writing a program that is supposed to solve a sudoko-like puzzle, Hashiwokakero. I have some code that looks like this:
if (bridgesLeft[row][col] == 1)
{
doSomething();
}
else if (bridgesLeft[row][col] == 2)
{
doSomethingElse();
}
else if (bridgesLeft[row][col] == 3)
{
doAnotherThing();
}
...
I realized that I put a bug in the doSomethingElse()
function, so rather than deleting that block, I added else if (bridgesLeft[row][col] == 2 && false)
to guarantee that the buggy function wouldn't run, just to make sure that was where my bug was coming from. Xcode gave me a warning, saying my doSomethingElse()
code would never run. It also gave me this option:
fix-it: Silence by adding parentheses to mark code as explicitly dead.
Clicking on this button changes
else if (bridgesLeft[row][col] == 2 && false)
to
else if (bridgesLeft[row][col] == /* DISABLES CODE */ (2) && false)
How do parentheses around the '2' mark this code as explicitly dead? What does this mean? If I leave the parentheses in, but take the && false
part out, the code block is still executed, so it's not actually making the code dead.
whatever && false
is false and will probably get rid of the whatever part. I guess this is more relevant if a function call is this whatever part. Putting that function call into parentheses might indicate that something odds happening. – Benedictus// doSomethingElse() temp remove because of bug in doSomethingElse
. – Kakemono