在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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

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

其他回答

在JavaScript中:

alert(111111111111111111111) // alerts 111111111111111110000

这对我在JSON中来回传递的一些64位键非常不利。

PHP

来自在线文档: string implode (string $glue, array $pieces) -用字符串连接数组元素 注意:由于历史原因,implode()可以以任意一种顺序接受其形参。

这是可行的:implode($someArray, $glue)

希望他们能在PHP 6中消除这些历史怪癖。

在Ruby中…

i=true
while(i)
   i=false
   a=2
end
puts defined?(a) // returns true

在统一中,

GameObject.Find("MyObject")

将正常返回对象。然而,如果你这样做:

GameObject.Find("MyObject").active = false;
//do other stuff
if (GameObject.Find("MyObject").active)
{
    //do stuff
}

然后您将得到一个空引用。在Unity iPhone中,这段代码通常在编辑器中正常工作,但在iPhone上运行时会导致SIGBUS。问题是GameObject.Find()将只定位活动对象,所以即使你只是检查它是否活动,你也会有效地调用if (null.active)。

为了使它正常工作,你必须在使它不活跃之前存储它。

GameObject obj = GameObject.Find("MyObject");
obj.active = false;
//do other stuff
if (obj.active)
{
    //do stuff
}

可以说,这是一种更好的实践,但Unity处理非活动对象的方式通常是相当奇怪的。它似乎卸载了大部分非活动对象(纹理等),但不是全部,因此非活动对象仍然会消耗大量内存。

Tcl中的连接是将两个字符串添加为一个字符串:

set s1 "prime"
set s2 "number"
set s3 $s1$s2
puts s3

输出为

primenumber