在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
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
还有很多这样的东西。点击这里阅读完整列表。
其他回答
在c++中,你可以从空指针调用静态方法——看!
class Foo {
public:
static void bar() {
std::cout << "WTF!?" << std::endl;
}
};
int main(void) {
Foo * foo = NULL;
foo->bar(); //=> WTF!?
return 0; // Ok!
}
这句话让我很意外……
在JavaScript中:
alert(111111111111111111111) // alerts 111111111111111110000
这对我在JSON中来回传递的一些64位键非常不利。
C++:
void f(int bitand i){ //WTF
i++;
}
int main(){
int i = 0;
f(i);
cout << i << endl; //1
return 0;
}
引用尼尔·弗雷泽的话(看那一页的末尾)
try {
return true;
} finally {
return false;
}
(在Java中,但在JavaScript和Python中行为显然是相同的)。其结果留给读者作为练习。
编辑:只要我们谈到这个问题,也要考虑到这一点:
try {
throw new AssertionError();
} finally {
return false;
}
在c#中
Math.Round(2.5)==2