在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
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.
其他回答
在JavaScript中,下面的构造
return
{
id : 1234,
title : 'Tony the Pony'
};
返回undefined是一个语法错误,因为在返回后的换行上偷偷地插入了分号。以下工作正如你所期望的那样:
return {
id : 1234,
title : 'Tony the Pony'
};
更糟糕的是,这个也可以(至少在Chrome中):
return /*
*/{
id : 1234,
title : 'Tony the Pony'
};
下面是同一个问题的一个变种,它不会产生语法错误,只是无声地失败了:
return
2 + 2;
c++最恼人的解析:
struct S
{
S() {} //default constructor
};
int main() {
S s(); // this is not a default construction, it declares a function named s that takes no arguments and returns S.
}
在ColdFusion中,数组从1开始。
C + + 1 xλ的:
[] (int x) { std::cout << x << std::endl; } ();
它们可能被滥用在一些奇怪的语法中:
[](){}();[]{[]{}();}();
这是完全有效的c++ 1x。
Python for循环中的else。
来自Python文档:
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print n, 'equals', x, '*', n/x
break
else:
# loop fell through without finding a factor
print n, 'is a prime number'
输出:
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3