[Wording] Why determine if the value to be written backwards

===============================================

 2019/8 / 27_ first edit              ccb_warlock          

 

===============================================

 

The origin of writing this article is to look at other people in a recent schema code always see something like this wording (param variable):

if (null == param)

{

  // todo

}

General logic is "if the argument is null, do what" directly equal to null is not good enough?

C # seems to be no difference?

Why he want to null in advance, so awkward wording write it?

 

After discussion and authors, mainly to prevent some of the pits in other languages. For example,

int value = 3if (value = 3)

{

    // todo

}

C #: this logic in the compiler will complain because "value = 3" is the result of int instead of bool.

C ++: this logic in the compiler is passed, because the value is greater than the integer 1, in the syntax of C ++, greater than integer default 1 can be converted to bool true, the compiler is not being given, but this logic does not meet the design . 

 

One of the benefits is that you can write backwards to avoid the pit grammar brings. 

int value = 3if (3 = value)

{

    // todo

}

So written backwards, C ++ compiler will be abnormal, thereby circumventing due to the development and oversight of buried pit.

 

Fitness written backwards when the wording in order to circumvent the language level of the pit, you can try to determine if usually write, to avoid some of the content from the pit father's writing: the conclusion.

Guess you like

Origin www.cnblogs.com/straycats/p/11415911.html