在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

在Java中(实际上,我最近在不同的SO帖子上写过这个):

    int x = 1 + + + + + + + + + + + + + 1;
    System.out.println(x);

其他回答

Perl:

可以编写一个完全由标点符号组成的程序。

这是怎么回事?!

Python的三元操作符

在Python中,C三元操作符(c++示例:bool isNegative = i < 0 ?True: false;)可用作语法糖:

>>> i = 1
>>> "It is positive" if i >= 0 else "It is negative!"
'It is positive'
>>> i = -1
>>> "It is positive" if i >= 0 else "It is negative!"
'It is negative!'

这并不奇怪,而是一种特征。奇怪的是,与C中的顺序(条件?答:b)。

A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.

Perl的$[(已弃用),这在之前关于通用Perl变量的另一篇文章中提到过,但它值得特别提到,并有更好的解释。对$[的更改仅限于当前范围。更多的信息以及如何使用它的含义;)可以在$[中找到,请访问http://www.perlmonks.org/index.pl/?node_id=480333

在JavaScript中,undefined是一个全局变量,其默认值为原始值undefined。你可以改变undefined的值:

var a = {};
a.b === undefined; // true because property b is not set
undefined = 42;
a.b === undefined; // false

由于undefined的可变性,通过typeof检查undefined通常是一个更好的主意:

var a = {};
typeof a.b == "undefined"; // always true