Hello,
I have an interesting point in mind. Often you want to use the properties of the language. If you have a logical expression in normal form, where the main operator in the Polish tree of the logical operations is an AND (&&) and the first operand is false, the language won't calculate the value of the other operands. Similarly, if the main operator in the Polish tree of the logical operations is an OR (||) and the first operan is true, the other operands won't be calculated. Let's see a few examples
//...
// Position is a class
private bool checkMate(ref int numberOfPlies, ref ChessPosition position, int maxNumberOfPlies, List<Move> moves)
{
if (numberOfPlies > maxNumberOfPlies)
return false;
position.makeMove(moves[numberOfPlies]);
if (!(position.getSuccessOfLastMove())))
return false;
numberOfPlies++;
return ((
((isCheckMate()) ||
((checkMate(ref numberOfPlies, ref position, maxNumberOfPlies, moves)))
));
}
//...
The above method checks whether a varitation leads to a checkmate from a given chess position and the checkmate is given in a certain amount of plies. Position is a class, its makeMove() method makes a move in the given position, its getSuccessOfLastMove() is true if the last move was valid and is false if the last move was not valid. Move is another class. Ply is a half-move in chess (Move = white moves and black moves, Ply = White or Black made a move). isCheckMate checks whether a given position is a checkmate.
We don't want to call checkMate if isCheckMate() is true, so we don't need other operation here than the usual ||.
However, here we want to evaluate all the operands:
//...
bool isThisFlowerYellowOrYellowish(Flower flower)
{
return (((flower.flowerColor == flower.yellow) OR
(flower.FlowerColor == flower.yellowish)) AND
(flower.setColorToYellowIfTheColorIsYellowish()));
}
//...
The code above is not a valid C# code, but let's see why we need an OR in C#.
In the example above we want to run the setColorToYellowIfTheCollorIsYellowish() even if we know the result of the total evaluation before evaluating the function, but the code is not working because we don't have an OR operation which calculates all the operands even if we can know the result. If this was possible, we would be able to not write the function in an alternative way.
//...
bool isThisFlowerYellowOrYellowish(Flower flower)
{
if (flower.FlowerColor == flower.yellowish)
return flower.setColorToYellowIfTheColorIsYellowish();
return (flower.flowerColor == flower.yellow);
}
//...
This is disgusting compared to the second example in my opinion. If we had an "OR" and an "AND" operator which are not optimised and evaluates all the operands no matter what, then the language would be richer with a feature, but, we can survive without these operators, because we have alternative solutions when needed and this is a very rare case.
In my opinion we don't need a "NOT" operator, because that's a unary operator and it would be similar with the ! operator.
In my opinion we shouldn't change the !, ||, &&, & and | operators because all the programmers are used to them. If they are changed in C#, the language will not have backwards compatibility.