在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
引用尼尔·弗雷泽的话(看那一页的末尾)
try {
return true;
} finally {
return false;
}
(在Java中,但在JavaScript和Python中行为显然是相同的)。其结果留给读者作为练习。
编辑:只要我们谈到这个问题,也要考虑到这一点:
try {
throw new AssertionError();
} finally {
return false;
}
其他回答
在JavaScript中:
alert(111111111111111111111) // alerts 111111111111111110000
这对我在JSON中来回传递的一些64位键非常不利。
在Java中可以抛出任何可抛出的东西。
class YourBoss extends Throwable {
}
public class Main{
public void main(String[] s) throws YourBoss {
try{
throw new YourBoss();
}catch(Exception e){
}catch(Error e){
}
}
}
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.
作为一名NHibernate爱好者,当我从Smalltalk听到be时,我非常激动……如。
a become: b
它直接将a对象更改为b,这使得编写惰性初始化代理变得很简单,因为所有对a的引用现在都将引用b。非常简洁!
我认为这是一种奇怪的语言特征,因为据我所知,没有其他语言具有这种能力。
我有点纠结:
1;
在perl中,模块需要返回true。