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

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


当前回答

在Python中:

>>> a[0] = "hello"
NameError: name 'a' is not defined
>>> a[0:] = "hello"
NameError: name 'a' is not defined
>>> a = []
>>> a[0] = "hello"
IndexError: list assignment index out of range
>>> a[0:] = "hello"
>>> a
['h', 'e', 'l', 'l', 'o']

这些切片分配也会给出相同的结果:

a[:] = "hello"
a[42:] = "hello"
a[:33] = "hello"

其他回答

s a=“a=”“a=”a“”,@a=“”“”2N“”“”,a=“c=”_(“”22“”?@a),@a“”,@a,a=“a”“,a(c)=”“S+”“_c,e=$T(@@a@(c))”,@a

这是COS (cache objectscript)中很好的一行代码。有趣的是,这里有5种不同的代码-间接*G模式

到目前为止,我遇到过的最奇怪的功能是BASIC方言中的“RETURN n”语句(不记得是哪一种了,这是大约28年前的事了)。“n”是可选的,默认为1。它可以是一个正数或负数,指示下一个执行的是与调用GOSUB相关的哪一行。

例如,下面将输出“30”:

10 GOSUB 200
20 PRINT "20"
30 PRINT "30"
100 END
200 RETURN +2

当我必须把一个用这种奇怪的BASIC语言编写的程序翻译成FORTRAN时,我遇到了这个问题。BASIC程序相当多地使用了这个特性,根据不同的条件返回不同的语句,我花了一段时间来理解逻辑流。一旦我理解了它,我就可以编写一个更简单的程序版本。不用说,更简单的FORTRAN版本比原来的BASIC程序bug更少。

对于那些从未使用过COBOL的人来说,这是一个常见的代码行,但它不做您可能想做的事情

图片XXX

这并不奇怪或令人惊讶,但这让我总是说WTF:

语法或标识符名称的大小写敏感性。

大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。

PHP对字符串中数值的处理。详见之前对另一个问题的回答,但简而言之:

"01a4" != "001a4"

如果你有两个包含不同数量字符的字符串,它们不能被认为是相等的。前导零很重要,因为它们是字符串而不是数字。

"01e4" == "001e4"

PHP doesn’t like strings. It’s looking for any excuse it can find to treat your values as numbers. Change the hexadecimal characters in those strings slightly and suddenly PHP decides that these aren’t strings any more, they are numbers in scientific notation (PHP doesn’t care that you used quotes) and they are equivalent because leading zeros are ignored for numbers. To reinforce this point you will find that PHP also evaluates "01e4" == "10000" as true because these are numbers with equivalent values. This is documented behaviour, it’s just not very sensible.