在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Python中:
abs((10+5j)-(25+-5j))
返回~18.03,根据毕达哥拉斯定理,这是点(10,5)和(25,5)之间的距离。之所以会出现这种情况,是因为Python的原生语言支持2+2j形式的复数。由于复数的绝对值形式为a+bj =根号下(a^2+b^2),我们得到距离,同时从一个复数减去另一个复数,然后应用abs(绝对)函数在它上面。
其他回答
腓backticks
从http://www.php.net/manual/en/language.operators.execution.php
PHP支持一种执行操作符:反撇号(' ')。注意,这些不是单引号!PHP将尝试作为shell命令执行反勾号的内容;输出将被返回(即,它不会简单地转储到输出;它可以赋值给一个变量)。
$output = `ls -al`;
echo "<pre>$output</pre>";
在代码中发现“instead of”是“相当容易的”。
这也很有趣:
经过一番折腾,我得出结论,反勾运算符(和shell_exec)的返回缓冲区有限。我的问题是,我正在处理一个超过50万行的文件,收到的回复远远超过10万行。短暂的停顿之后,我收到了大量来自grep的关于管道关闭的错误。
C和c++中的三联体。
int main() {
printf("LOL??!");
}
这将打印LOL|,因为trigraph ??!转换为|。
为什么c#的List<T>.AddRange()不让我添加T的子类型的元素?阀门列表< T > () ! 微软只需要多写一行代码:
public void AddRange<S>(
IEnumerable<S> collection
) where S : T
在JavaScript(和Java)中,你可以转义这样有趣的字符:
var mystring = "hello \"world\"";
如果你想把回车放到字符串中,那是不可能的。你必须像这样使用\n:
var mystring = "hello, \nworld";
这是正常的,也是意料之中的——至少对于一种编程语言来说。奇怪的是你也可以像这样转义一个实际的回车:
var mystring = "hello, \
world";
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.