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

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


当前回答

FORTRAN并不是一个真正的WTF时刻,而更像是一个“为什么我需要输入所有这些垃圾时刻”

IF(12 .gt. 11) THEN
 // Do some magic
ENDIF

“.gt.”在我玩这门语言的时候把我弄糊涂了,直到我意识到它是“>”符号。哦,我多喜欢不学生物,不用天天接触这些垃圾

其他回答

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

Java缓存范围为-128到127的整数对象实例。如果你不知道这一点,下面的内容可能会让你有些意想不到。

Integer.valueOf(127) == Integer.valueOf(127); // true, same instance
Integer.valueOf(128) == Integer.valueOf(128); // false, two different instances

我很惊讶居然没有人提到Visual Basic的7个循环结构。

For i As Integer = 1 to 10 ... Next
While True ... End While
Do While True ... Loop
Do Until True ... Loop
Do ... Loop While True
Do ... Loop Until True
While True ... Wend

因为粘!你面前的条件实在是太复杂了!

Processing (processing.org)是一种基于Java的语言。简单来说,处理编译器是将特定于处理的语法转换为Java的Java预处理器。

由于语言的设计,它有一些惊喜:

Processing的类被编译成Java内部类,这会引起一些麻烦,比如私有变量并不是真正私有的

class Foo {
  private int var = 0; // compiles fine
}

void setup() {
  Foo f = new Foo();
  print(f.var); // but does not causes compile error
}

同样缺少draw()函数会导致事件处理程序不被调用:

// void draw() {} // if you forgot to include this
void mousePressed() {
  print("this is never called");
}

回想起来,FORTRAN的计算goto是相当奇怪的。维基百科告诉我一些基础知识胜过它。

另一个著名的最爱是Algol 60的名称参数调用传递。