Measure the test taker's knowledge about the top ten strange features in programming languages.

Source: Internet
Author: User
Each programming language has its own "quirks", such as Strange syntaxes, distinctive functions, or implementation methods that do not conform to standards. Each programming language has its own "quirks", such as Strange syntaxes, distinctive functions, or implementation methods that do not conform to standards. Programmers also have their own habits, which will make many programmers, even some experienced developers, feel crazy when facing a new language. The features of these languages sometimes become a stumbling block for programmers, and sometimes programmers will gradually understand these features and gradually adapt to and like them. Although there are countless features in all languages, there is not so much discussion among programmers. in this article, we list the top 10 strange features in the most crazy programming language for programmers.

1. in JavaScript, '+' is a join operator.

Strange feature: In JavaScript, '+' is an overloaded operator. it is both a plus sign (+) between numbers and a connector between strings. If one of the operands in a '+' operation is a string, JavaScript converts the other operand to a string. in this case, '+' 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 weak language. But for Python, although '+' is also the concatenation operator between strings, but Python is a strong-type language, when programmers want to add strings and integers together, the program will report an error.

2. a class in Perl must return TRUE.

Strange feature: Classes in Perl often end with a return 1 statement, because if the last statement in the class does not return a true value, an error will occur.
Cause Analysis: the classes in Perl can contain initialization tasks and subroutines. After the file is loaded, Perl checks whether the program is successfully executed by looking for a TRUE return value. Even if the class does not contain the initialization code, Perl returns the TRUE value at the end of the expected class; otherwise, an exception is thrown.

3. three character groups in C and C ++

Strange Features: C and C ++ support nine three-character groups, which will convert the three-character group into a single character before subsequent processing, such '??! 'Will be converted to/, which will make the source code more difficult to read and sometimes cause unexpected problems.
Cause Analysis: The three-character group was initially used to help early C programmers to print characters that are not on the keyboard, such as curly braces.

4. PHP is not sensitive to uppercase and lowercase letters

Strange feature: Identifiers in many programming languages are case-sensitive, but in PHP functions and class names, case-insensitive. This is okay, but what puzzles programmers most is that PHP's variable names, constants, and class attributes are case sensitive.
Cause Analysis: Most likely, PHP is a mature programming language gradually developed by CGI scripts.

5. The value 0 in Ruby indicates true.

Strange feature: in Ruby, 0 represents TRUE, which is the opposite of other languages such as C and Python. in these languages, 0 represents FALSE, this also makes many new Ruby developers confused.
Cause Analysis: In Ruby, only the bool values FALSE and nil are equal to FALSE, and all others are TRUE. 0 is the same as other numbers.

6. use spaces in Python to separate "blocks"

Strange Features: neither punctuation nor keywords are used. Python uses a unique indentation level to determine which part of a line of code belongs. Errors may occur when spaces or tabs are mixed.
Cause Analysis: This may be related to Python in order to produce better readable code and reduce typing, and many code editors now support automatic indentation.

7. the array subscript in C language is like a pointer operation.

Strange feature: pointers in C language, in addition to using I as the subscript in array a and representing it as a [I], C allows the same element to be expressed as I [a].
Cause Analysis: in C language, arrays are like pointers in memory, so a [I] = * (a + I) = * (I + a) = I [a].

8. pre-defined variables in Perl

Strange feature: Perl has a long string of special variables, all of which have confusing names. For non-Perl experts, they often need to query the Perl documentation to understand the meaning of the code.
Cause Analysis: these variables are usually information about program execution, such as process ID ($), error message ($ @), regular Expression Matching ($ ^ R ).

9. automatically insert a semicolon in JavaScript

Strange feature: In JavaScript, the use of a semicolon as the end of a statement is only used as an option because it will automatically insert a semicolon, for example, after a line break. But this usually produces an error when no exception is thrown.


Cause Analysis: insert a semicolon for convenience, so that programmers, especially new programmers, feel that JavaScript syntax is very easy.

10. Integer type conversion in Java

Strange feature: Java will automatically convert the original type to an object. for example, to convert the int type to an Integer object, the default value of the Integer object is from-128 to 127. This problem occurs when '=' is used to compare two integers with the same value (TRUE is returned only when-128-127 is used, and FALSE is returned for others ).
Cause Analysis: This conversion will reduce the programmer's code volume and improve performance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.