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

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


当前回答

引用尼尔·弗雷泽的话(看那一页的末尾)

try {
    return true;
} finally {
    return false;
}

(在Java中,但在JavaScript和Python中行为显然是相同的)。其结果留给读者作为练习。

编辑:只要我们谈到这个问题,也要考虑到这一点:

try {
    throw new AssertionError();
} finally {
    return false;
}

其他回答

反向波兰符号。这意味着实参在函数之前。换句话说,2加2就是2 +。

具有WTF特性的语言包括Forth、Postscript(是的,激光打印机的Postscript)和Factor。

我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:

void someWindowsFunction() {
    BITMAPINFOHEADER header = {sizeof header};

    /* do stuff with header */
}

这条微妙的线条达到了以下效果:

Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).

Perl:

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

这是怎么回事?!

英语中的虚拟语气。

等等,你是说编程语言吗?然后在C中使用(宏)绕过宏()的预处理器#定义。例如,如果有人使用#define free(…),(free)(…)将与free(…)不同。

这并不奇怪或令人惊讶,但这让我总是说WTF:

语法或标识符名称的大小写敏感性。

大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。