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

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


当前回答

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

class (TArray) DerivedArray
  var someField = 56;
end

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

其他回答

在SQL Server中,如果你在生产代码中使用select *,你可能会遇到一个令人讨厌的意外。无论如何,使用select *并不被认为是一个好的实践,但了解一些有趣的行为是很好的。

参见问题“select * from table”vs“select colA,colB etc from table”在SqlServer2005中有趣的行为了解更多细节

VBScript的With block:

With xml.appendChild(xml.createElement("category"))
  .setAttribute("id",id)
  .setAttribute("keywords",keywords)
  With .appendChild(xml.createElement("item"))
    .setAttribute("count",count)
    .setAttribute("tip",tip)
    .appendChild(xml.createTextNode(text))
  End With
End With

Perl的sub没有真正的参数列表,只有@_数组。同时,sub会自动变平传入的参数。

我不明白为什么这是一个持久的功能;这反映了几年前我不得不在TI-86 BASIC上做的事情,因为这门语言没有足够的特色。

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

在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){
   }
  }
}