It's just out of curiosity, I ask ...
99% of the code that I see anywhere, when using "IF", will be in the format "If (RValue == LValue) ...". Example:
If (variableABC == "Hello World") ...
There are other examples when I see the opposite:
If ("Hello World" == variableABC)
Does anyone know how this started and why it was made?
This is done due to this error in C and C ++:
if (variableABC = "Hello World") ... ^ (Watch here)
Thus, we have a compilation error:
if ("Hello World" = variableABC) ^ (Watch here)
For example, C # and Java do not need this trick.
The latter is done to prevent unintentional assignments if you mistakenly use the assignment operator = instead of the equality operator == '
=
==
Some languages ββdo not allow assignment in an if condition, in which case this is normal.
In languages ββthat accept assignments under if conditions, I always prefer to go in the latter case.
This is due to errors that developers often make write = instead of ==. In C ++, integers can be treated as logical and you did not get errors at compile time.
Source: https://habr.com/ru/post/913745/More articles:full-screen script, curses-style, updating table output (a la top) on unixen - pythonUsing Json.NET serializer in MVC4 project - serializationWhat are the benefits of using Spring Data neo4j only when directly using neo4j? - spring-data-neo4jScala Cake Pattern: splitting large components into separate files - scalaIs there a more efficient method than loops for something that requires conditional validation? - loopsHierarchical taxonomy in literate searches using RavenDb / Lucene? - luceneCan I create FILE * with memory mapping in C / Objective-C on iOS? - cWrite two threads at the same time - cThe value of the items in the depbar setting - erlangLong SQL file starts SQL Server from memory (22,000 lines) - sqlAll Articles