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

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


当前回答

在Java中,

Int x = 010;

这将x赋值为8。

在Java中,任何前面带0的整数都被假定为八进制。

其他回答

在PHP中,你可以这样做:

System.out.print("hello");

我很惊讶没有人提到大多数类c语言中丑陋的开关case实现

switch (someInt) {
    case 1:
    case 2: System.out.println("Forgot a break, idiot!");
    case 3: System.out.println("Now you're doing the wrong thing and maybe need hours to find the missing break muahahahaha");
            break;
    default: System.out.println("This should never happen -,-");        
}

好在新语言正确地实现了它。

有些奇怪——VBScript有一个Null关键字和一个Nothing关键字(Null是丢失的数据,Nothing是丢失的对象)。为什么不只有一个关键词…?大多数其他语言似乎都可以用一个!

Visual Basic 6.0当然还有“经典ASP”代码(因为它使用VBScript)也有同样的奇怪之处。在Visual Basic的新旧版本中,我们都有DBNull。

然而,这种情况正在改善,就像Visual Basic一样。NET Null终于消失了,所以Null不再使用,只有Nothing和DBNull被使用。

一般来说,弱类型。

C:

printf("%c\n", 'a' + 3);

PHP:

echo 5 + "3";

还有太多其他语言。

PHP对字符串中数值的处理。详见之前对另一个问题的回答,但简而言之:

"01a4" != "001a4"

如果你有两个包含不同数量字符的字符串,它们不能被认为是相等的。前导零很重要,因为它们是字符串而不是数字。

"01e4" == "001e4"

PHP doesn’t like strings. It’s looking for any excuse it can find to treat your values as numbers. Change the hexadecimal characters in those strings slightly and suddenly PHP decides that these aren’t strings any more, they are numbers in scientific notation (PHP doesn’t care that you used quotes) and they are equivalent because leading zeros are ignored for numbers. To reinforce this point you will find that PHP also evaluates "01e4" == "10000" as true because these are numbers with equivalent values. This is documented behaviour, it’s just not very sensible.