Code readability: avoid negative statements
Negative statements are more difficult to read and not always the straightforward approach will result in the better code from the first attempt. Let's say the procedure should react on certain condition and ignore all overs. Compare these two snippets:
if (!isGreen)vs.
{
StopMachine();
TurnOnAlarm();
RunForYourLife();
}
if (isGreen) return;The second one is more readable but more verbose (so as human language). Also the second one is obviously a separate method while the first one could be an inline code. In this case refactoring to the better readability resulted in more cohesive code.
StopMachine();
TurnOnAlarm();
RunForYourLife();
If you're a tough C# programmer and reading both snippets is no brainer for you - consider this SQL nonsense:
DELETE FROM Cross_Reference_Between_Left_And_Right WHERE xId INvs.
(SELECT xId FROM Left_Table WHERE xNamePrefix NOT IN ('pro','contra'))
DELETE FROM Cross_Reference_Between_Left_And_Right WHERE xId NOT INFor me personally, the first one is an eyesore.
(SELECT xId FROM Left_Table WHERE xNamePrefix IN ('pro','contra'))