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

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


当前回答

下面这个我觉得很奇怪:

在C/ c++中,你可以有尽可能多的分号,至少在MS c++中:

int main(void)
{
 cout<<"Hello World";;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;
 return 0;;;;;;;;;;;;;;;;;;;;;;;
}

其他回答

下面的答案与这个关于数组的答案类似。

在Powershell中,像其他动态语言一样,字符串和数字在某种程度上是可以互换的。然而,Powershell无法下定决心。

PS> $a = "4"    # string
PS> $a * 3      # Python can do this, too
444
PS> 3 * $a      # Python doesn't do it this way, string repetition is commutative
12
PS> $a + 3      # Python gives a mismatched types error
43
PS> 3 + $a      # Python would give an error here, too
7

如果变量是整数而不是字符串,则操作是可交换的。

PS> $a = 4      # integer
PS> $a * 3
12
PS> 3 * $a
12
PS> $a + 3
7
PS> 3 + $a
7

当有疑问时,做一个模型:

PS> $a = "4"
PS> $b = 3
PS> [int] $a * [int] $b
12

你也可以使用[float]。

在Javascript中,我认为以下是等价的:

a['title'] = "Syntactic sugar is good for yr teeth.";
a.title = "Syntactic sugar is good for yr teeth.";

在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充满了奇怪但整洁的特性。

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

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

foreach也是如此:

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

我不知道这是否是真的,但我们偶然发现VS FORTRAN(66或77)不支持递归。递归是偶然的,我们的默认F77支持它很漂亮,但当我们把源代码IBM - Whatta混乱。