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

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


当前回答

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语言中,

 int x = 1;
 int y = x++ + ++x;
 printf("%d", y);

是模棱两可的,打印什么取决于编译器。编译器可以在计算++x之前或在语句的末尾存储x++的新值。

在PHP中,你可以这样做:

System.out.print("hello");

在Visual Basic 7及以上版本中,我发现实现了短路逻辑求值以保持与遗留的Visual Basic <=6代码的兼容性,有点WTF:

而且 (MSDN) OrElse (MSDN)

好吧,这也是我最喜欢的很难找到的虫子…将以0开头的整数视为八进制数。这导致了一个只会在早上8点到10点之间显示的错误:

有一次,我帮助构建了一个自动回归测试,在晚上通过cron执行。在一个20人的团队中,它几乎适用于每个人——除了一个开发人员偶尔会抱怨自动测试失败,但当手动运行时,一切都很好。这甚至一次都无法人工复制。

好吧,原因是,我们根据date命令的输出进行了一些统计计算(在bash中),这只在早上8:00到9:59期间失败,因为我们将小时值读取为“08”(这是一个非法的八进制值,而“01”-“07”是有效的八进制值,从“10”开始,所有内容都被再次视为十进制)……

在SQL

NULL不等于NULL

所以你不能:

WHERE myValue == NULL

这将总是返回false。

NULL != NULL