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

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


当前回答

在类C语言(包括C本身)中,你可以使用“向下到”操作符:

for (x = 20; x --> 0;) {
    print x;
}

这将打印从19到0的数字。

其他回答

这可能已经被提到了,但是——

PHP对八进制值的处理:

$a = 07; // 7 (as it should be)
$b = 08; // 0 (would be an error in any sensible language)
$c = 018; // 1 (again, should have been an error)
$d = 0A; // error (as it should be)

请看这里:http://bugs.php.net/bug.php?id=29676

还要注意关于这个错误的评论——Derick称其为一个特性(引用“fix”表示),而不是一个错误,他声称它会“在脚本中使用数字的所有情况下显著降低PHP的速度”——但是,为什么PHP会引发一个0A错误呢?

我认为人们可以写一整本书来讲述PHP的古怪之处……

作为一名NHibernate爱好者,当我从Smalltalk听到be时,我非常激动……如。

a become: b

它直接将a对象更改为b,这使得编写惰性初始化代理变得很简单,因为所有对a的引用现在都将引用b。非常简洁!

我认为这是一种奇怪的语言特征,因为据我所知,没有其他语言具有这种能力。

我一直在想为什么最简单的程序是:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

然而它可以是:

print "Hello World!"

也许这是为了吓唬计算机科学专业的学生……

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.

ruby中的隐含变量\constants和可变常量