在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在PHP中,函数名不区分大小写。这可能会导致您认为php中的所有标识符都不区分大小写。再猜一遍。变量区分大小写。WTF。
function add($a, $b)
{
return $a + $b;
}
$foo = add(1, 2);
$Foo = Add(3, 4);
echo "foo is $foo"; // outputs foo is 3
echo "Foo is $Foo"; // outputs Foo is 7
其他回答
这并不奇怪或令人惊讶,但这让我总是说WTF:
语法或标识符名称的大小写敏感性。
大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。
2000年Perl Journal's obfusated Perl Contest的最佳参赛作品:
#:: ::-| ::-| .-. :||-:: 0-| .-| ::||-| .:|-. :||
open(Q,$0);while(<Q>){if(/^#(.*)$/){for(split('-',$1)){$q=0;for(split){s/\|
/:.:/xg;s/:/../g;$Q=$_?length:$_;$q+=$q?$Q:$Q*20;}print chr($q);}}}print"\n";
#.: ::||-| .||-| :|||-| ::||-| ||-:: :|||-| .:|
代码由作者在http://mysite.verizon.net/les.peters/id2.html详细解释
在Java中从文本文件中读取一行。
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("filename"));
String str;
str = in.readLine();
if (str != null) {
...
}
} catch (IOException e) {
...
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {}
}
啊。虽然我承认这并不奇怪……只是邪恶。: -)
更短、更习惯的版本:
try {
BufferedReader in = new BufferedReader(new FileReader("filename"));
try {
String str = in.readLine();
while (str != null) {
str = in.readLine();
}
} finally {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
在(MRI/C) Ruby和MacRuby(而不是JRuby)中,整洁的系统相关溢出会导致年份翻转,然后出现更大数量的本地时间错误。这不是一个常见的问题,但很奇怪:
$ ruby -version
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
$ irb
>> Time.at(67767976233550799)
=> Tue Dec 31 23:59:59 -0500 2147483647
>> Time.at(67767976233550800)
=> Wed Jan 01 00:00:00 -0500 -2147483648
>> Time.at(67768036191694799)
=> Wed Dec 31 23:59:59 -0500 -2147481749
>> Time.at(67768036191694800)
ArgumentError: localtime error
...
Maybe IRB bug!!
不过,这可能特定于64位环境。
在c#中,以下代码会生成编译器错误“无法从方法组转换为委托”。虽然背后的逻辑是合理的,但我还是觉得很奇怪。
control.BeginInvoke(delegate { DoSomething(); });