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

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


当前回答

通知7。一个有效程序的例子:

    Chomsky is a room. 
    A thought is a kind of thing. 
    Color is a kind of value. 
    The colors are red, green and blue. 
    A thought has a color. It is usually Green. 
    A thought can be colorful or colorless. It is usually colorless. 
    An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously." 
    A manner is a kind of thing. 
    Furiously is a manner. 
    Sleeping relates one thought to one manner. 
    The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation. 
    Colorless green ideas sleep furiously. 

像图灵机模拟器这样的其他愚蠢的东西可以找到。

其他回答

ActionScript 3:

当一个对象被它的接口使用时,编译器不识别从object继承的方法,因此:

IInterface interface = getInterface();
interface.toString();

给出一个编译错误。 解决方法是将类型转换为Object

Object(interface).toString();

PHP:

. 和+运算符。它有其合理的解释,但“a”+“5”= 5仍然显得尴尬。

Java(以及任何IEEE754的实现):

System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1);

输出0.9999999999999999

来自边远吗?

在c++中,你可以做:

std::string my_str;
std::string my_str_concat = my_str + "foo";

但你不能:

std::string my_str_concat = "foo" + my_str;

操作符重载通常服从WTF。

PHP中的变量

PHP中一个奇怪的特性,它允许你从其他变量的内容中创建和分配变量(警告,未经测试的代码):

$a = 'Juliet';
$$a = 'awesome'; // assigns a variable named $Juliet with value 'awesome'

echo '$a';       // prints Juliet
echo '${$a}';    // prints awesome
echo '$Juliet';  // prints awesome

好吧,假设我们有这样的东西:

$bob = 'I\'m bob';
$joe = 'I\'m joe';
$someVarName = 'bob';
$$someVarName = 'Variable \'bob\' changed';

用各种间接的方式来找点乐子怎么样:

$juliet = 'Juliet is awesome!';
$func = 'getVarName'

echo '${$func()}'; // prints 'Juliet is awesome!'

function getVarName() { return 'juliet'; }

在Matlab中,以下内容可能会让你感到惊讶,特别是如果你习惯了Python:

>> not true

ans =

     0     0     0     0
>> not false

ans =

     0     0     0     0     0

这里有两个奇怪的特征。第一个是a b被解释为a('b'),因此非真被解释为not('true')。第二个奇怪的特征是没有任何字符返回0(大概是因为在matlab中没有false或true,只有0或1)。