I didn't read the rest of the reply's but I'm sure somebody said this:
Your here if "a is not 1" OR "b is not 2". Not AND.
Essentially:
if (!($a == 1 && $b == 2))
{
print "We're here only if a is not 1 OR b is not 2!\n";
}
Which, if you "boolean negate" all things in parenthesis (multiply by -1), can be reduced to:
if ($a != 1 || $b != 2)
{
print "We're here only if a is not 1 OR b is not 2!\n";
}
Conclusion, there is no LOGICAL reason to have an empty block just to negate an if statement.
ALL statements can be resolved using BOOLEAN logic, all..
However, as a long time C++ programmer, I can tell you that I do this all the time.
Why?
As a placeholder if the condition were to someday be true.
However the reality is that
this notation: if (!($a == 1 && $b == 2))
is preffered
over this: if ($a != 1 || $b != 2)
because it separates the classes into distinct "what is" and "what isn't",
which is what you wan't.
sln
Following up on my own post..
Ok, I just read the other posts.
I am not saying you don't have the 'logic' portion of your brain
when I make this recomendation. Instead, I'm offering a suggestion on how
to develop it.
Its a natural ability to resolve boolean expressions.
Programmers, over time develop this naturally.
Realistaclly, probably %40 of initial codeing errors, and
%20 of remaining errors after fixes, are attributed to errors
in logic, boolean errors.
I call them "conceptual" errors. They are what testers are for.
The people who are very good in boolean logic, can read code
as fast as people read books. They are well paid.
Reading the boolean logic in code is the first line of error detection
when debugging large code. It scrapes off the first layer.
Its re-read for deeper "conceptual" errors, design errors.
By that time, all the flaws are known. The fix is harder.
Well paid people.
If you were good in math since childhood, say intermediate algebra,
could almost do it in your head, you will probably be a good programmer
if you study.
So my suggestion is that if you have access to college, you take a course
called "Formal Symbolic Logic 101". It's all about Boolean symbolism,
sort of Electrical Engineering'ish. In essence, it takes the words, sentences,
paragraphs of .. debate speaches, for instance... or news articles, or whatever..
And formulates BOOLEAN equations to represent them. The equations are then resolved,
ie: reduced, to test the validity of the representation. Its TRUE or FALSE, and why.
Although there are many more constructs of logic in language (human language), that
comprise the conditions, in that context there are many more gradations of fallicy
than can be incorporated into computer language. As such, there are logic laws,
rules, falicy's, that can be easily identified.
The big thing in "Formal Symbolic Logic" is that logic is incorporated to interpret
language. And guess what? The very same formal logic symbolism laws are used in CS and EE and ME
and all the other sciences.
Its an elective in Junior College, take it!
sln