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

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


当前回答

在Java中,字符串如何处理==操作符取决于它是如何构造的,这存在一些不一致性。

String a = "Hello";
String b = "Hello";
System.out.println(a == b ); // prints true.
String c = new String("Hello");
String d = new String("Hello"); 
System.out.println(c == d ); // prints false

其他回答

这是我的两分钱。在c++中:

int* t = new int(15);
delete t;

JavaScript是面向对象的,对吧?因此,在文字字符串和数字上运行方法应该是可行的。比如"hello". touppercase()和3.toString()。第二个是语法错误,为什么?因为解析器期望一个数字后面跟一个点是一个浮点字面值。这不是WTF, WTF是你只需要再加一个点就可以了:

3..toString()

原因是字面上的3。被解释为3.0,3.0. tostring()工作正常。

当我在大学的时候,我用一种叫做SNOBOL的语言做了一点工作。整个语言虽然很酷,但却是一个大WTF。

它的语法是我见过的最奇怪的。而不是GoTo,你使用:(标签)。当你有:S(label)(成功/true时的goto标签)和:F(label)(失败/false时的goto标签)并且你在一行中使用这些函数检查某些条件或读取文件时,谁还需要if呢?所以这个表述是:

H = INPUT :F(end)

将从文件或控制台读取下一行,如果读取失败(因为到达EOF或任何其他原因),将转到标签“end”。

然后是$ sign操作符。它将使用变量中的值作为变量名。所以:

ANIMAL = 'DOG'
DOG = 'BARK'
output = $ANIMAL

将在控制台上显示'BARK'值。因为这还不够奇怪:

$DOG = 'SOUND'

将创建一个名为BARK的变量(参见上面分配给DOG的值),并赋予它一个“SOUND”的值。

你看得越多,情况就越糟。我所发现的关于SNOBOL的最好的陈述(来自链接文本)是“该语言的强大功能及其相当惯用的控制流特性使得编写后的SNOBOL4代码几乎不可能阅读和理解。”

INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.

两个字:多重继承。这毫无意义,只会制造麻烦。

编辑——我指的是c++中的MI,而不是Java和其他语言中的mixins之类的。