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

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


当前回答

Perl充满了奇怪但整洁的特性。

If可以用在语句之前或之后,就像这样:

print "Hello World" if $a > 1;    
if ($a > 1) { print "Hello World"; }

foreach也是如此:

print "Hello $_!\n" foreach qw(world Dolly nurse);

其他回答

在FoxPro中,如果我没记错的话,每个命令都可以缩写为4个字符,其他的都被忽略,所以READ, READY, READINESS都是一样的——前4个字符之后的都被忽略。向我解释的人喜欢这个功能,但我觉得它很恐怖。

c++最恼人的解析:

struct S
{
    S() {} //default constructor
};

int main() {

    S s(); // this is not a default construction, it declares a function named s that takes no arguments and returns S.
}

在JavaScript中,看到!!第一次使用A(作为一种转换为布尔值的方式)。

在JavaScript中:

2 == [2]

// Even stranger
2 == [[[2]]]

// And down-right nutty
var a = { "abc" : 1 };
a[[[["abc"]]]] === a["abc"]; // this is also true

幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切: 为什么2 ==[2]在JavaScript?

Perl充满了奇怪但整洁的特性。

If可以用在语句之前或之后,就像这样:

print "Hello World" if $a > 1;    
if ($a > 1) { print "Hello World"; }

foreach也是如此:

print "Hello $_!\n" foreach qw(world Dolly nurse);