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

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


当前回答

学习PowerShell时发现:

试着猜一下结果数组是什么样的:

$a = 1, 2
$b = 1, 2+3
$c = 1, 2*3

答案:

1, 2
1, 2, 3
1, 2, 1, 2, 1, 2

哎哟!它动摇了我对PowerShell及其开发人员的信心。

其他回答

很简单,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!

Python 2。X演示了一个糟糕的列表理解实现:

z = 4
s = [z*z for z in range(255)]
print z

这段代码返回254。列表推导式的变量与上定义的变量冲突。

Python 3。x已经处理了这个特性,但是闭包仍然对外部变量使用动态链接,并在函数式python编程器中引入了许多wtf

def mapper(x):
    return x*x
continuations = [lambda: mapper(x) for x in range(5)]
print( [c() for c in continuations])

此代码显然返回[16,16,16,16,16]。

foo是什么数据类型?

SELECT TOP 1
   NULL AS foo
INTO
   dbo.bar
FROM
   sys.columns --trivial

为什么所有东西都归零?

SELECT CAST('' AS int), CAST('' AS datetime), CAST('' AS float)

...除了这

SELECT CAST('' AS decimal)

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

C++:

void f(int bitand i){ //WTF
    i++;
}
int main(){
    int i = 0;
    f(i);
    cout << i << endl; //1
    return 0;
}