在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在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文件和构造一个正常运行的正则表达式一样乏味。)
其他回答
在Scala中,没有操作符,只有方法。所以a + b - c实际上等于a +(b) -(c)在这里,它等于Smalltalk。但是,与Smalltalk不同的是,它考虑了优先级。规则基于第一个字符,因此一个假设的方法*+将优先于一个叫做+*的方法。做了一个例外,以便任何以=结尾的方法都将具有与==——含义相同的优先级!!和!=(非假设方法)具有不同的优先级。
所有ASCII字母的优先级最低,但所有非ASCII (unicode)字符的优先级最高。如果你写了一个比较两个int型的方法,那么2 + 2 = 1 + 3将会编译并为真。如果你用葡萄牙语写é,那么2 + 2 é 1 + 3会导致错误,因为它会看到2 + (2 é 1) + 3。
而且,在Scala中操作符的WTF中,所有以:结尾的方法都是右关联的,而不是左关联的。这意味着1::2::Nil等价于Nil.::(2).::(1)而不是1.::(2).::(Nil)。
在fortran中(当然是77,可能在95中也是如此),未声明的变量和以I到N开头的参数(“In”组)将是INTEGER,所有其他未声明的变量和参数将是REAL(源)。这与“在某些情况下可选的空白”相结合,导致了最著名的错误之一。
正如弗雷德·韦伯在1990年的《另类民间传说:计算机》一书中所说:
I worked at Nasa during the summer of 1963. The group I was working in was doing preliminary work on the Mission Control Center computer systems and programs. My office mate had the job of testing out an orbit computation program which had been used during the Mercury flights. Running some test data with known answers through it, he was getting answers that were close, but not accurate enough. So, he started looking for numerical problems in the algorithm, checking to make sure his tests data was really correct, etc. After a couple of weeks with no results, he came across a DO statement, in the form: DO 10 I=1.10 This statement was interpreted by the compiler (correctly) as: DO10I = 1.10 The programmer had clearly intended: DO 10 I = 1, 10 After changing the . to a , the program results were correct to the desired accuracy. Apparently, the program's answers had been "good enough" for the sub-orbital Mercury flights, so no one suspected a bug until they tried to get greater accuracy, in anticipation of later orbital and moon flights. As far as I know, this particular bug was never blamed for any actual failure of a space flight, but the other details here seem close enough that I'm sure this incident is the source of the DO story.
我认为这是一个很大的WTF,如果DO10I被作为DO10I,并且反过来,因为隐式声明被认为是类型REAL。这是个很棒的故事。
在c++中,你可以做:
std::string my_str;
std::string my_str_concat = my_str + "foo";
但你不能:
std::string my_str_concat = "foo" + my_str;
操作符重载通常服从WTF。
在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队!:)
特点:Bash, Korn shell (ksh93)和Z shell都允许使用带或不带美元符号的变量下标数组:
array[index]=$value
array[$index]=$value
加上美元符号,会得到10000的期望值:
unset array
for i in {1..10000}
do
((array[$RANDOM%6+1]++))
done
unset total
for count in ${array[@]}
do
((total += count))
done
echo $total
陌陌性:如果你从RANDOM中移除美元符号,总数将随机变化,甚至大于10000。
类似地,这将产生3而不是2:
a=1; ((r[a++]++)); echo $a
你不能在这里用美元符号,因为这是赋值运算(a在lhs上)虽然你可以用间接的方法,但是双重求值还是会发生。
原因:对于美元符号,变量展开在算术求值之前执行,因此只执行一次。如果没有美元符号,它将执行两次,一次是计算查找的索引,另一次是计算赋值的索引(因此,实际上,循环中第一步的赋值可能看起来像array[4] = $array[6] + 1,这完全打乱了数组)。