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

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


当前回答

ruby中的隐含变量\constants和可变常量

其他回答

PHP

$ php -r '::'
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

WTF ? http://en.wikipedia.org/wiki/Scope_resolution_operator

为什么不说意外的T_SCOPE_RESOLUTION_OPERATOR ?

Tcl在解释器中虚拟化的时间钩子非常奇怪: http://www.tcl.tk/cgi-bin/tct/tip/233.html

基本上,它允许你让解释器使用一些其他的时间数据源,例如,先在模拟器中运行硬件测试,然后替换计时器函数,对真实的东西运行相同的测试。

ActionScript 3:

当一个对象被它的接口使用时,编译器不识别从object继承的方法,因此:

IInterface interface = getInterface();
interface.toString();

给出一个编译错误。 解决方法是将类型转换为Object

Object(interface).toString();

PHP:

. 和+运算符。它有其合理的解释,但“a”+“5”= 5仍然显得尴尬。

Java(以及任何IEEE754的实现):

System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1);

输出0.9999999999999999

在一个奇怪的银行系统中使用RSL编程语言。数组有内置类TArray。但如果你从它继承,每个实例变量都成为数组的一个元素。

class (TArray) DerivedArray
  var someField = 56;
end

var a = DerivedArray();
PrintLn(a.Size);     // => 1
PrintLn(a[0]);       // => 56 

在Java中从文本文件中读取一行。

BufferedReader in = null;
try {
   in = new BufferedReader(new FileReader("filename"));
   String str;
   str = in.readLine();
   if (str != null) {
      ...
   } 
} catch (IOException e) {
   ...
} finally {
   try {
      if (in != null) {
         in.close();
      }
   } catch (IOException e) {}
}

啊。虽然我承认这并不奇怪……只是邪恶。: -)

更短、更习惯的版本:

try {
   BufferedReader in = new BufferedReader(new FileReader("filename"));
   try {
       String str = in.readLine();
       while (str != null) {
          str = in.readLine();
       } 
    } finally {
        in.close();
    }
} catch (IOException e) {
    e.printStackTrace();
}