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

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


当前回答

我喜欢Smalltalk中缺少运算符优先级

2 * 3 + 4 * 5 = 6 + 4 * 5 = 10 * 5 = 50

而不是

2 * 3 + 4 * 5 = 6 + 4 * 5 = 6 + 20 = 26

这是由于smalltalk的对象性质和消息从左向右传递的事实。如果消息*以数字3作为参数发送给2,则该消息的响应为6。太棒了,如果你觉得邪恶,你甚至可以用猴子来修补它。

其他回答

另一个C-ism。

int i= 0;
while( i != 12 ) {
    /* Some comment 
    i += 1;
    /* Another comment */
}

为什么不行?棉绒会告诉你。然而,C编译器通常会轻松地忽略这一点。我也是。

当我发现问题出在哪里的时候,那真是太棒了。

在C或c++中,使用宏可以获得很多乐趣。如

#define FOO(a,b) (a+b)/(1-a)

如果传入FOO(bar++,4),它将使a增加两次。

在ruby/python/c中,你可以像这样连接字符串:

a = "foo" "bar"
print a # => "foobar"

Perl的许多内置变量:

$# — not a comment! $0, $$, and $? — just like the shell variables by the same name $ˋ, $&, and $' — weird matching variables $" and $, — weird variables for list- and output-field-separators $! — like errno as a number but strerror(errno) as a string $_ — the stealth variable, always used and never seen $#_ — index number of the last subroutine argument... maybe @_ — the (non)names of the current function... maybe $@ — the last-raised exception %:: — the symbol table $:, $^, $~, $-, and $= — something to do with output formats $. and $% — input line number, output page number $/ and $\ — input and output record separators $| — output buffering controller $[ — change your array base from 0-based to 1-based to 42-based: WHEEE! $} — nothing at all, oddly enough! $<, $>, $(, $) — real and effective UIDs and GIDs @ISA — names of current package’s direct superclasses $^T — script start-up time in epoch seconds $^O — current operating system name $^V — what version of Perl this is

还有很多这样的东西。点击这里阅读完整列表。

我肯定会给Perl提供多个可怕的例子:

if(!$#var)

or

if($mystring =~ m/(\d+)/) {