在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在PHP中:
<?php
$o = new stdClass;
echo count($o);
?>
..打印1。一直不知道为什么。
其他回答
我一直想知道这个函数在Java Core库的Math类中的用途:
static double expm1(double x); // Returns e^x - 1.
在Python中:
>>> x=5
>>> 1<x<10
True
>>> 1<x<3
False
不是一个WTF,但是一个有用的特性。
我最喜欢的奇怪的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).
PHP的列表构造:
$array = array(0,1,2);
list (,,$x) = $array;
$x == 2; // true
一些早期的动态语言(包括,如果我没记错的话,Perl的早期版本)没有弄清楚什么是好的动态,什么是坏的动态。所以他们中的一些人允许这样做:
1 = 2;
在这句话之后,下列情况是正确的:
if(1 + 1 == 4)