在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在awk中,数组从索引1开始,这是最不容易混淆的。
其他回答
交替:在许多语言中的事物之间交替:
boolean b = true;
for(int i = 0; i < 10; i++)
if(b = !b)
print i;
乍一看,b怎么可能不等于它自己呢? 这实际上只会打印奇数
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详细解释
Perl
my %h1 = map { $_ => 1 } qw/foo bar baz/; // construct an 'is_member' type lookup table
my %h2 = map { "$_" => 1 } qw/foo bar baz/;
第二行是一个语法错误,即使对一个有经验的perl程序员来说,它看起来是一样的。perl的缺点是总是试图做你想做的,而不是你说的。
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.
在SQL server(至少MS)中:
这将总是求值为false:
IF @someint <> NULL
考虑到:
DECLARE @int INT
SET @int = 6
IF @int <> NULL
BEGIN
Print '@int is not null'
END
ELSE
BEGIN
Print '@int is evaluating to null'
END
输出将是:
@int is evaluating to null
必须这样写:
IF @someint IS NOT NULL
BEGIN
END
谁让英语专业的人加入了SQL队!:)