在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
这是我最喜欢的一个,你可以在Java中不使用main()来执行println。
这将编译和运行,给出println,但也有一个异常(java.lang。NoSuchMethodError:主要)
class Test {
static {
System.out.println("I'm printing in Java without main()");
}
}
其他回答
A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.
这个古老的PHP宠儿本身并不完全是WTFish,但作用域解析错误是许多开发人员看到的事情之一,值得给一些WTF的爱:
$class = new StdClass();
$class::test();
PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 3
交替:在许多语言中的事物之间交替:
boolean b = true;
for(int i = 0; i < 10; i++)
if(b = !b)
print i;
乍一看,b怎么可能不等于它自己呢? 这实际上只会打印奇数
Java有一整本关于它们的书。
书http://www.javapuzzlers.com/lg-puzzlers-cropped.jpg
爪哇益智游戏
腓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的关于管道关闭的错误。