在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在c#中
Math.Round(2.5)==2
其他回答
大约20年前,我用一个编译器为一种叫做Coral的语言工作,它允许我声明只写变量!
不过,这是有道理的,因为它们是全球性的,被用作一种信号机制。一个进程写入值,另一个进程读取值。
在MOD_REWRITE
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ $1/ [R,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/$ $1\.php [NC,L]
将会导致:
"file.php > file > file.php > file > file.php > file > ..."
最后:
Error 500 Too Many Redirects
(一般来说,我发现编辑.htaccess文件和构造一个正常运行的正则表达式一样乏味。)
Java;使所有对象实例都是互斥对象。
下面的c#代码抛出NullReferenceException而不是打印1:
static void SomeMethod(string format, params object[] args)
{
Console.WriteLine(args.Length);
}
static void Main(string[] args)
{
SomeMethod("blabla", null, "Ok here"); // print 2
SomeMethod("blabla", null); // exception
}
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.