在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在ColdFusion
Struct(又名Java HashMap)是通过引用传递的。
你可能认为其他数据类型的行为就像Java…
数组是按值传递的,wtf!
List只是一个普通的逗号分隔的字符串!
其他回答
任何东西都会自动将任何类名和成员名复数或单数。
例如,Linq-to-Sql
转变;
有时你会在perl方法的第一行中看到它来读取self指针
我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:
void someWindowsFunction() {
BITMAPINFOHEADER header = {sizeof header};
/* do stuff with header */
}
这条微妙的线条达到了以下效果:
Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).
不知道这是不是一个功能。对一些人来说,是的,但对另一些人来说,这可能是一种令人讨厌的行为。不管怎样,我认为这是值得一提的。
在Python中,内置函数round()在Python 2x和Python 3x之间的行为略有不同。
对于Py 2x,
>>> round(0.4)
0.0
>>> round(0.5)
1.0
>>> round(0.51)
1.0
>>> round(1.5)
2.0
对于Py 3x,
>>> round(0.4)
0
>>> round(0.5)
0
>>> round(0.51)
1
>>> round(1.5)
2
我只是不熟悉Py 3x中的round()与0的工作方式。
Py 2x和Py 3x中round()的文档。
在Scala中,没有操作符,只有方法。所以a + b - c实际上等于a +(b) -(c)在这里,它等于Smalltalk。但是,与Smalltalk不同的是,它考虑了优先级。规则基于第一个字符,因此一个假设的方法*+将优先于一个叫做+*的方法。做了一个例外,以便任何以=结尾的方法都将具有与==——含义相同的优先级!!和!=(非假设方法)具有不同的优先级。
所有ASCII字母的优先级最低,但所有非ASCII (unicode)字符的优先级最高。如果你写了一个比较两个int型的方法,那么2 + 2 = 1 + 3将会编译并为真。如果你用葡萄牙语写é,那么2 + 2 é 1 + 3会导致错误,因为它会看到2 + (2 é 1) + 3。
而且,在Scala中操作符的WTF中,所有以:结尾的方法都是右关联的,而不是左关联的。这意味着1::2::Nil等价于Nil.::(2).::(1)而不是1.::(2).::(Nil)。