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

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


当前回答

Malbolge编程语言的完整版本:http://en.wikipedia.org/wiki/Malbolge

其他回答

这个C程序在x86和x86-64上输出不同的结果:

#include <stdio.h>
int main (void)
{
  long a = -1; 
  unsigned b = 1; 
  printf ("%d\n", a > b); 
  return 0;
}

C# has a feature called "extension methods", which are roughly analogous to Ruby mix-ins - Essentially, you can add a method to any pre-existing class definition (for instance, you oould add "reverse()" to String if you were so inclined). That alone is fine- The "Weird" part is that you can add these extension methods, with a method body and everything, to an interface. On the one hand, this can be handy as a way to add a single method to a whole swath of classes which aren't part of the same inheritance tree. On the other, you're adding fleshed out methods to interfaces, essentially breaking the very definition of an interface.

我一直是PHP错误的忠实粉丝,当在一行中使用两个冒号时脱离上下文:

解析错误:语法错误,第3行/path/to/file/error.php中的T_PAAMAYIM_NEKUDOTAYIM异常

第一次遇到这种情况时,我完全被弄糊涂了。

在MySQL中字符串比较是不区分大小写的。

> SELECT * FROM blah WHERE foo = 'BAR';
> SELECT * FROM blah WHERE foo = 'Bar';
> SELECT * FROM blah WHERE foo = 'bAr';

都是等价的。它们不仅会匹配任何看起来像'bar'的foo值(例如,如果foo = 'bar',它将匹配bar, bar, bar等)。

在JavaScript中,void不是关键字,不是类型声明,也不是变量名,也不是函数,也不是对象。Void是一个前缀操作符,类似于-、——、++和!你可以给任何表达式加上前缀,这个表达式的值将是undefined。

它经常被用在bookmarklet和内联事件处理程序中,比如下面这个比较常见的例子:

<a href="javascript:void(0)">do nothing</a>

在这个例子中使用它的方式使它看起来像一个函数调用,而实际上它只是一种获得原始未定义值的过于聪明的方法。大多数人并没有真正理解JavaScript中void的真正本质,这可能会导致许多讨厌的bug和奇怪的意想不到的事情发生。

不幸的是,我认为void操作符是在JavaScript中获得未定义值的唯一真正保证的方法,因为未定义,正如在另一个回答中指出的,是一个可以重新赋值的变量名,而{}。a可以被Object.prototype.a = 'foo'打乱

更新:我想到了另一种生成undefined的方法:

(function(){}())

嗯,有点啰嗦,返回“undefined”是它的目的就更不清楚了。