在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

c# yield语句,并不奇怪,但非常有用。

http://msdn.microsoft.com/en-us/library/9k7k7cf0 (VS.80) . aspx

其他回答

在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。这是个很棒的故事。

在FoxPro中,如果我没记错的话,每个命令都可以缩写为4个字符,其他的都被忽略,所以READ, READY, READINESS都是一样的——前4个字符之后的都被忽略。向我解释的人喜欢这个功能,但我觉得它很恐怖。

在我看来,在c#中能够将超出范围的整数转换为枚举是非常奇怪的。想象一下这个枚举:

enum Colour
{
    Red = 1,
    Green = 2,
    Blue = 3
}

现在,如果你写:

Colour eco;
eco = (Colour)17;

编译器认为这很好。还有运行时。

请看这里了解更多细节。

两个字:多重继承。这毫无意义,只会制造麻烦。

编辑——我指的是c++中的MI,而不是Java和其他语言中的mixins之类的。

Perl充满了奇怪但整洁的特性。

If可以用在语句之前或之后,就像这样:

print "Hello World" if $a > 1;    
if ($a > 1) { print "Hello World"; }

foreach也是如此:

print "Hello $_!\n" foreach qw(world Dolly nurse);