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

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


当前回答

INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.

其他回答

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

图片XXX

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

在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]。

学习PowerShell时发现:

试着猜一下结果数组是什么样的:

$a = 1, 2
$b = 1, 2+3
$c = 1, 2*3

答案:

1, 2
1, 2, 3
1, 2, 1, 2, 1, 2

哎哟!它动摇了我对PowerShell及其开发人员的信心。

在c#中: A = cond ?B: c; 如果“b”和“c”是“赋值不兼容”,你永远不会得到结果,即使“a”是对象。 它是ms中最常用和最愚蠢的实现运算符。有关比较,请参阅D语言中的实现(关于类型推断的注意)。

PHP

$ php -r '::'
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

WTF ? http://en.wikipedia.org/wiki/Scope_resolution_operator

为什么不说意外的T_SCOPE_RESOLUTION_OPERATOR ?