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

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


当前回答

在PHP中,你可以这样做:

System.out.print("hello");

其他回答

在PHP中,如下:

<?php $foo = 'abc'; echo "{$foo";

是语法错误。

如果你真的想要{,后面跟着$foo的内容,你必须使用。:

<?php $foo = 'abc'; echo '{' . $foo;

在Ruby中…

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

在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();
}

在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

其余的这些都没有令人震惊的Ruby触发器操作符:

p = proc {|a,b| a..b ? "yes" : "no" }

p[false,false]    => "no"
p[true,false]     => "yes"
p[false,false]    => "yes"   # ???
p[false,true]     => "yes"
p[false,false]    => "no"

是的,程序状态存储在解释器的解析树中。这就是为什么开发一个兼容的Ruby实现要花很长时间的原因。但是我原谅你,Ruby