在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Ruby中…
i=true
while(i)
i=false
a=2
end
puts defined?(a) // returns true
其他回答
早期的FORTRAN,空格不重要。(anti-Python !)
DO 20 I = 1, 10
含义:从这里循环到第20行,I从1到10。
DO 20 I = 1. 10
含义:将1.10分配给名为DO20I的变量。
有传言说这个漏洞毁了一个太空探测器。
APL(除了ALL),在一行中编写任何程序的能力。
例:在APL中,康威的生命游戏一行:
替代文本 http://catpad.net/michael/APLLife.gif
如果这句台词都不是WTF,那什么都不是!
这是一个视频
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.
在C或c++中,使用宏可以获得很多乐趣。如
#define FOO(a,b) (a+b)/(1-a)
如果传入FOO(bar++,4),它将使a增加两次。
为什么c#的List<T>.AddRange()不让我添加T的子类型的元素?阀门列表< T > () ! 微软只需要多写一行代码:
public void AddRange<S>(
IEnumerable<S> collection
) where S : T