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

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


当前回答

好吧,既然问题是断断续续的,我就加入到“有趣”中来

Go(又名Issue9)使用大写的可见性:

如果你用大写字母命名某个东西,它就会被公众访问。 如果你使用小写,它将被包保护:

包装外可见:

func Print(v ...) { 
}

包外不可见

func print( v ... ) {
}

你可以在这个原始答案中找到更多。

其他回答

我很惊讶居然没有人提到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

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

在SQL

NULL不等于NULL

所以你不能:

WHERE myValue == NULL

这将总是返回false。

NULL != NULL

很简单,Erlang有很多。例如,标点符号的三种形式,

a_function(SomeVariable) ->
  statements_end_with_commas(),
  case PatternMatching of
    0 -> now_we_end_with_semicolon;
    true -> except_the_last_one
  end.

%%  Function definitions end with periods!

这不是一个奇怪的功能,事实上,如果你仔细想想,它是完全有意义的,但还是给了我一个WTF时刻。

在c++(和c#)中,基类的子类不能访问基实例上的私有和受保护成员。

class Base {
protected:
 m_fooBar;
};

class Derived: public Base {
public:
 void Test(Base& baseInstance) {
  m_fooBar=1; //OK
  baseInstance.m_fooBar = 1; //Badness
  //This, however is OK:
  ((Derived&)baseInstance).m_fooBar = 1; //OK
 }
};

我很惊讶没有人提到大多数类c语言中丑陋的开关case实现

switch (someInt) {
    case 1:
    case 2: System.out.println("Forgot a break, idiot!");
    case 3: System.out.println("Now you're doing the wrong thing and maybe need hours to find the missing break muahahahaha");
            break;
    default: System.out.println("This should never happen -,-");        
}

好在新语言正确地实现了它。