在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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++中的MI,而不是Java和其他语言中的mixins之类的。

Java有一整本关于它们的书。

书http://www.javapuzzlers.com/lg-puzzlers-cropped.jpg

爪哇益智游戏

我一直是PHP错误的忠实粉丝,当在一行中使用两个冒号时脱离上下文:

解析错误:语法错误,第3行/path/to/file/error.php中的T_PAAMAYIM_NEKUDOTAYIM异常

第一次遇到这种情况时,我完全被弄糊涂了。

s a=“a=”“a=”a“”,@a=“”“”2N“”“”,a=“c=”_(“”22“”?@a),@a“”,@a,a=“a”“,a(c)=”“S+”“_c,e=$T(@@a@(c))”,@a

这是COS (cache objectscript)中很好的一行代码。有趣的是,这里有5种不同的代码-间接*G模式

在JavaScript中:

var something = 12;

function nicelyCraftedFunction()
{
  something = 13;
  // ... some other code
  // ... and in Galaxy far, far away this:
  if( false ) // so the block never executes:
  { 
    var something; 
  }
}
nicelyCraftedFunction(); // call of the function

通常你会期望某个变量的值是13。 但在JavaScript中不是这样——变量有函数作用域,所以后面的声明会影响上游的一切。

在使用C/ c++ /Java表示法的语言(如JS)中,你会期望变量具有块范围,而不是像这样…

因此,编译器甚至可以从最终生成的字节码中删除的死代码块仍然会对正常执行的其余代码产生副作用。

因此,在调用函数之后,某些东西仍然是12 -不变的。