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

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


当前回答

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

其他回答

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的缺点是总是试图做你想做的,而不是你说的。

在一个奇怪的银行系统中使用RSL编程语言。数组有内置类TArray。但如果你从它继承,每个实例变量都成为数组的一个元素。

class (TArray) DerivedArray
  var someField = 56;
end

var a = DerivedArray();
PrintLn(a.Size);     // => 1
PrintLn(a[0]);       // => 56 

我最喜欢的c++之一:

#include <iostream>
using namespace std;
int main()
{
    cout <<  3 << 5  << endl;
    cout << (3 << 5) << endl;
    return 0;
}

当然,这很容易解释,但它让刚开始编程的学生摸不着头脑!

С#:

var a = Double.Parse("10.0", CultureInfo.InvariantCulture); // returns 10
var b = Double.Parse("10,0", CultureInfo.InvariantCulture); // returns 100

在不变区域性中,逗号不是小数点符号,而是组分隔符。

据我所知,对于一些地区的新手程序员来说,这是一个常见的错误。

在俄亥俄州立大学,他们用一种叫做Resolve/ c++的杂种c++语言教授编程。Resolve/ c++对一切都使用契约式设计方法。它要求您在编译后的注释中对组件和方法进行数学建模,从而强制您维护方法和对象之间的require /ensure关系。