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

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


当前回答

在ColdFusion

Struct(又名Java HashMap)是通过引用传递的。

你可能认为其他数据类型的行为就像Java…

数组是按值传递的,wtf!

List只是一个普通的逗号分隔的字符串!

其他回答

通知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. 

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

在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)。

在Python中:

>>> a[0] = "hello"
NameError: name 'a' is not defined
>>> a[0:] = "hello"
NameError: name 'a' is not defined
>>> a = []
>>> a[0] = "hello"
IndexError: list assignment index out of range
>>> a[0:] = "hello"
>>> a
['h', 'e', 'l', 'l', 'o']

这些切片分配也会给出相同的结果:

a[:] = "hello"
a[42:] = "hello"
a[:33] = "hello"

在awk中,数组从索引1开始,这是最不容易混淆的。

这并不奇怪或令人惊讶,但这让我总是说WTF:

语法或标识符名称的大小写敏感性。

大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。