Why does C # not accept logical operators in the form of words ("and", "or", "not", etc.) with current operators?

Mine if stetement:

if (!string.IsNullOrEmpty(Person.Name))
        // some code

I think that "!" the operator is less readable when writing imperative code,

Do you agree with me, is the following code more readable?

if (not string.IsNullOrEmpty(Person.Name))
            // some code

I'm not talking about replacing current operators, but where is the problem if the language accepts them?

+3
source share
4 answers

There are several good reasons:

  • , . , AND , (& vs &). VB (ish) AND AndAlso. . , .

  • . , , , - , , , .

  • , C, Java, Objective-C ++. 40 (?) - . , .

  • "", "" "" - ! && & .

  • , , .

+11

, "", , VB - . ,

If value Is Not Null Then
   'do something
End If

, #! && || , , , .

, , .

+7

, , . . , , . , , , . . , Stack Overflow!

+1

. . , AND (& &), - false, , , OR (||), - true, .

//...
// 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)))
           ));
}
//...

, , . - , makeMove() , getSuccessOfLastMove() , , . - . Ply - (Move = , Ply = White Black ). isCheckMate , .

checkMate, isCheckMate() , , ||.

:

//... bool isThisFlowerYellowOrYellowish ( ) {   return ((( .flowerColor == flower.yellow)            (flower.FlowerColor == flower.yellowish))           (Flower.setColorToYellowIfTheColorIsYellowish())); } //...

#, , OR #. setColorToYellowIfTheCollorIsYellowish(), , , OR, , . , .

//...
bool isThisFlowerYellowOrYellowish(Flower flower)
{
    if (flower.FlowerColor == flower.yellowish)
        return flower.setColorToYellowIfTheColorIsYellowish();
    return (flower.flowerColor == flower.yellow);
}

//...

, . "OR" "AND", , , , , , .

-, "", , ! .

-, !, ||, & &, | , . #, .

EDIT:

, , , , , .

0
source

Source: https://habr.com/ru/post/1763227/


All Articles