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

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


当前回答

Go的伪常数Iota:

type ByteSize float64
const (
_ = iota;   // ignore first value by assigning to blank identifier
KB ByteSize = 1<<(10*iota); MB; GB; TB; PB; YB;
)   

其他回答

在C:

int main() {
  int i = 0;
  int array[] = {1,2};

  return (i[array] + 1 == array[i]);
}

这个程序将返回1 (true)。

命名空间解析顺序

为例。

namespace foo.bar.xyz{
  public class Foo{
    Exception e;   // you'll get compile time error here....
  }
}

因为

namespace foo.bar.Exception{
  class HowDoMyWayException : ApplicationException {
   // because someone did this
  } 
}

在Java中可以抛出任何可抛出的东西。

class YourBoss extends Throwable {
}
public class Main{
  public void main(String[] s) throws YourBoss {
   try{
    throw new YourBoss();
   }catch(Exception e){
   }catch(Error e){
   }
  }
}

在Perl中(没有“使用严格”或“使用警告”):

if(true==undef)
{
    print "True\n";
}
else{
    print "False\n";
}
if(undef)
{
    print "True\n";
}
else{
    print "False\n";
}
if(true)
{
    print "True\n";
}
else{
    print "False\n";
}

打印:

True
False
True

这个古老的PHP宠儿本身并不完全是WTFish,但作用域解析错误是许多开发人员看到的事情之一,值得给一些WTF的爱:

$class = new StdClass();
$class::test();

PHP Parse error:  syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 3