在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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及其开发人员的信心。

其他回答

在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

PHP (?)

第一:(未设置)类型转换。

$a = 1;
$b = (unset)$a;
var_dump($a); // 1
var_dump($b); // NULL

用法:http://www.php.net/manual/en/language.types.type-juggling.php # 89637

第二:= NULL和unset()函数之间的区别。

$c = 10;
$d = &$c;
$c = NULL;
var_dump($c); // NULL
var_dump($d); // NULL


$e = 10;
$f = &$e;
unset($e);
var_dump($e); // NULL
var_dump($f); // 10 - WTF?

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");
}

2000年Perl Journal's obfusated Perl Contest的最佳参赛作品:

#:: ::-| ::-| .-. :||-:: 0-| .-| ::||-| .:|-. :||
open(Q,$0);while(<Q>){if(/^#(.*)$/){for(split('-',$1)){$q=0;for(split){s/\|
/:.:/xg;s/:/../g;$Q=$_?length:$_;$q+=$q?$Q:$Q*20;}print chr($q);}}}print"\n";
#.: ::||-| .||-| :|||-| ::||-| ||-:: :|||-| .:|

代码由作者在http://mysite.verizon.net/les.peters/id2.html详细解释

Perl:

可以编写一个完全由标点符号组成的程序。

这是怎么回事?!