Each programming language has its own "quirks", such as strange syntax, unusual functionality, or a substandard implementation. Programmers also have their own habits, which can make many programmers, even some experienced developers, in the face of a new language will feel crazy. The characteristics of these languages can sometimes become a stumbling block for programmers, and in some cases programmers will slowly understand these characteristics and gradually adapt and like them. Although there are countless features in all languages, programmers are always talking about less than that, and in this article we list 10 of the most bizarre features in the programming languages that make programmers crazy.
1. JavaScript ' + ' is a join operator
Strange feature: In JavaScript, ' + ' is an overloaded operator, both a plus sign (+) between numbers and a connector between strings. If one of the operands is a string in a ' + ' operation, JavaScript converts the other operand to a string, and ' + ' is a join operator, so the result of ' 1 ' + 1 is ' 11 '.
Cause analysis: The root cause of this problem is that JavaScript is a weakly typed language. But like Python, although ' + ' is also a join operator between strings, Python is a strongly typed language, and when programmers want to add strings and integers together, the program will give an error.
2. A class in Perl must return True
Strange feature: Classes in the Perl language often end with a return 1 statement, because if the last statement in the class does not return a ture value, an error occurs.
Cause Analysis: Classes in Perl can contain some initialization work and subroutines. When the file is loaded, Perl begins to check whether the program executed successfully by looking for a true return value. Even if there is no initialization code part in the class, Perl expects the class to return a true value at the end, otherwise throws an exception.
3. Three-character groups in C and C + +
Strange features: C and C + + support 9 Three-character groups, which convert three-character groups to a single character before subsequent processing, such as '??! ' will be converted/, the result will make the source code more difficult to read, and sometimes unexpected problems occur.
Cause Analysis: The three-character group was originally used to help the early C programmers out some characters that were not in the keyboard, such as curly braces.
4. Case Insensitive in PHP
Strange feature: Identifiers in many programming languages are case-sensitive, but in PHP's functions and class names, casing is not sensitive. This is fine, but the most confusing thing for programmers is that PHP's variable names, constants, and class properties are case-sensitive.
Cause analysis: Most likely, PHP is a programming language that has evolved from CGI scripts to maturity.
5.0 in Ruby means ture
Strange feature: In Ruby, the value of 0 represents true, which is the exact opposite of other languages such as C, Python, and 0 in these languages is false, which is confusing for many new developers learning Ruby.
Cause analysis: Ruby only has bool value false and nil equals false, all other true,0 is the same as other numbers.
6. Use empty Glyd to "block" in Python
Strange feature: Neither punctuation nor keywords, Python uses a unique indentation level to determine which part of a line of code belongs. The wrong number of spaces or the mix of spaces and tab keys will produce an error.
Cause Analysis: This may be related to Python in order to produce more readable code, less typing, and now many code editors support automatic indentation.
7. The array subscript in the C language is like a pointer operation.
Strange characteristic: The pointer in C language, in addition to the I as subscript in array A, expressed as A[i],c also allows the same element to be represented as i[a].
Cause analysis: In C, an array is like a pointer in memory, so there is a[i] = * (a+i) = * (i+a) = I[a].
8. Pre-defined variables in Perl
Strange feature: Perl has a long list of special variables, all of which have confusing names. For non-Perl experts, they often need to query the Perl documentation to understand what the code means.
Cause analysis: These variables are often used to provide information about program execution, such as process ID ($$), error message ($@), and regular expression matching ($^r).
9. JavaScript automatically inserts semicolons
Strange feature: The end of using semicolons as a statement in JavaScript is only an option because it automatically inserts semicolons, such as after a newline character. However, this usually results in an error when no exception is thrown.
Cause analysis: Inserting semicolons is for convenience, making it easy for programmers, especially novice programmers, to think of JavaScript syntax.
Type conversions with integer participation in Java
Strange feature: Java automatically converts the original type to an object, such as converting int to an integer object, the value of the default integer object is from 128 to 127. This creates a problem when using ' = = ' to compare two integers with the same value (only 128-127 returns true and the rest returns false).
Cause analysis: This translates into less code for programmers and better performance.