在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在找函数吗?为什么不是一门语言呢?
我喜欢PHP,但它总是这样构建:“哦,糟了!我忘了这个!让我们在函数"中添加另一个参数,结果如下:
Str_replace ($search, $replace, $subject…) Strstr ($subject, $search,…)
注意额外的下划线和参数的不同顺序。
这里还有一些东西
$a = array( 'a', 'b', 'c', 'd');
print_r($a); //Prints array( 0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd');
unset($a[2]); //Destroys the element 2 of the list
print_r($a); //Prints array( 0 => 'a', 1 => 'b', 3 => 'd');
其他回答
我最喜欢的奇怪的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).
在C或c++中,使用宏可以获得很多乐趣。如
#define FOO(a,b) (a+b)/(1-a)
如果传入FOO(bar++,4),它将使a增加两次。
COMEFROM是我见过的最奇怪,也可能是最没用的语言功能。
其次是三元运算符,因为它违反了优化的第一条规则。它带来的危害大于它解决的问题。它的危害更大,因为它使代码可读性更差。
并不是一个真正的语言功能,但有趣/很棒的功能使用是Duff的设备。
In C
a[i++] = i;
它会编译,但很少执行您认为它应该执行的操作。优化更改会产生截然不同的结果。它在不同平台上的运行方式也不同。
然而,编译器对此非常满意。
INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。
COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.