Home >Backend Development >PHP Problem >10 language features that confuse programmers
Each language has its own unique features, such as peculiar syntax, unusual functions, or non-standard execution methods. Therefore, no matter whether you are a newbie or an experienced player, you will suddenly get drunk when looking at a certain feature. The article summarizes 10 "weird" features that are often mentioned.
1. Javascript: + is a connector
Problem description: In JS, the + sign is used between numbers and can be used as a regular addition; but if it encounters characters, it can also be used as a character connector. For example: the result of '1' + 1 is 11.
Cause analysis:
The fundamental reason is that JS is a weakly typed language. For example, Python also uses the + sign as the character connector, but because it is a strongly typed language, once it finds that a character is added to an integer, it will prompt that this is an error operation.
Opinions of netizens:
“The problem is that this is an unpredictable mandatory silent conversion, which is easy to ignore.” Anonymous
“JS should handle this situation by throwing exceptions.” crgwbr
“Use + to perform character concatenation is simply a nightmare. ”Matteo Riva
2. Perl: The module must return a TRUE value
Problem description: In most cases, the Perl module must end with a 1; statement, otherwise , if the return value of the last statement is not TRUE, the system will report an error.
Cause analysis:
The Perl module contains initial code and subroutines. When the module file is loaded, Perl will determine whether the code was successfully executed based on whether TRUE is returned. Even if there is no initial code, Perl still expects the last statement to return TRUE, otherwise an error will be reported.
ifier |
Problem description: For example, when the system sees ??!, it will automatically convert it to |, and when it sees ??(, it will convert it to [. This can easily cause unexpected results, and will greatly reduce the code Readability. Cause analysis: In the early days of programming, certain special characters, such as braces, could not be typed directly on the keyboard, so this indirect method was used. Opinions from netizens: “If you are as knowledgeable as Google, you must not understand what ??!??!” Isaac “Since the three-letter word was introduced in 1977, C has become obscure and difficult to understand.” Martin Beckett 4. PHP: Case sensitive processingProblem description: PHP’s case processing is confusing, distinguishing in some places and not in others. For example: variable names, constant names are distinguished; function names, method names, and class names are not distinguished. Analysis of the cause: It is probably an artifact that emerged during the development of PHP from a CGI script set to a mature programming language Netizens’ opinion: “This is why PHP programmers are accustomed to naming functions with underscores instead of underscores. The reason for adopting camel case naming. ”paperstreet7 In PHP, everything is possible! ”Grzechooo 5. Ruby: 0 as a true value Problem description: In Ruby, a 0 value is equivalent to a TRUE value. . This is a nightmare for programmers with C and Python background. Cause analysis: Only the boolean values FALSE and nil are equivalent to FALSE, and the rest are equivalent to TRUE. 2, 3, etc. will be treated the same. Opinions of netizens: “This is simply crazy, although the original intention is well-intentioned.” Chris Lutz “0==true! I am a C language brain. Almost collapsed! "Kenny 6. Python: Divide levels by number of spaces Problem description: Different from using keywords or punctuation, PY uses indentation levels to divide each line of code clearly The incorrect number of spaces (or the inconsistent number of spaces and transposition characters) may cause the program to report errors Cause analysis: The PY author’s intention is to make the code more readable and reduce unnecessary input. I hope that programmers themselves should take the responsibility of maintaining code clarity. Netizens’ opinions: “Sincerely, this is the fundamental reason why I stay away from PY.” wazoox “If we really need something like this. Enforcement mechanism, are we really too lazy! "Joris Meys 7. C: The working mode of array index is equivalent to that of pointer Problem description: In C, a[i] and i[a] are interchangeable, and both writing methods can produce the same result. The result. Cause analysis: In C, there is no difference between arrays and pointers for memory blocks, that is to say: a[i] = *(a + i) = *(i + a ) = i[a]. Netizens’ opinion: “This is worthless in the C language confusing code competition. "Confusion" "I think this reveals the core of the C language, pointers and more direct dealing with memory. ”Michael Neale 8. Perl’s: Predefined variables Problem description:Perl has a very long list of special variables, and the names in them are very complicated (although there are corresponding long English words). Therefore, unless you are a senior Perl developer, it is common to read the Perl documentation repeatedly.
Cause analysis:
These variables have different meanings, such as: process ID ($$), error message ($@), regular expression matching ($^R).
Netizens’ opinions:
“Very annoying!” MatrixFrog
“Maybe a boon for streamlined developers.” niXar
“The problem with these variables is: they cannot be found through Google!” malvim
9. JavaScript: Automatic semicolon insertion
Problem description:
JS uses semicolon as a sign of the end of a statement, and will insert it by itself, even if the code breaks. This often leads to errors.
Cause analysis:
The original intention of automation is to bring convenience, especially to novices.
Netizens’ opinions:
“If we always regard users as fools when designing language features, problems will arise.” Rob Van Dam
“Automatic semicolon insertion is the most troublesome thing about JS One of the places. ”fennec
10. Java: Autoboxing and Integer caching
Problem description:
Java will automatically convert basic type data into objects (autoboxing), such as converting int to An Integer object. At the same time, by default, the value of the cached Integer object is -128 to 127. In this case, there will be a problem when using == to compare two Integer objects with the same value (TRUE within -128 and 127, and the rest is FALSE)
Cause analysis:
The automatic boxing mechanism reduces the code Input volume, while Integer caching improves processing speed.
Opinions of netizens:
“Fortunately, I am just a C# programmer.” Will
“This is not a mistake, but it gives us a reason to use primitive types (such as: booleans) for number processing. ”RaviWallau