I mean, what’s the point? Let the code flow naturally after the ‘if’ and leave more unlikely situations for ‘else’ (displaying error for instance). In the ‘if’ block, you can put cases that are more natural for your game. A player wants to deal damage to living enemies. It is more common, as dead bodies are usually waiting for being cleaned up and are less attractive for the player. So:
If (!enemy.IsDead()) { enemy.TakeDamage(); } else { enemy.AddForce(FORWARD); // Profane the corpse }
It increases readability and stresses the expected game flow. If an attacker tells Mr. Wayne “Give me that wallet, or else…,” Mr. Wayne should give the wallet back, move on and doesn’t care about “else.” It’s the standard course of the situation and that solution should be considered first.
Common dude, just wrote a IsAlive() function 🙂 The problem with negation in the first IF is that coders often misses the “!”. If you really like to do still use this approach, at least wrote == false in the end. the false keyword get highlighted by most of the IDEs.