在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Javascript中,我认为以下是等价的:
a['title'] = "Syntactic sugar is good for yr teeth.";
a.title = "Syntactic sugar is good for yr teeth.";
其他回答
C预处理器及其用法。特别是预处理器元编程和使用预处理器生成可移植代码——完全是胡扯。
在Python中,每个字符串都包含空字符串。
answer = input("Enter 'Y[es] or N[o]:")
if answer in 'YyNn': # verify input
process(answer)
只要在上面的查询中点击return就会将答案设置为空字符串,将if答案传递给…测试,并被处理为正确答案。更简洁地说:
>>> "ABCDEFGHIJ".__contains__("")
True
像往常一样,Python在这里的行为在数学和逻辑上都是无可挑剔的。就像我在很久以前的集合论课上回忆的那样:空集合是每个集合的成员。
当我偶尔被它咬到的时候,它仍然让我感到惊讶,但我不会有其他的方式。
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.
In C
a[i++] = i;
它会编译,但很少执行您认为它应该执行的操作。优化更改会产生截然不同的结果。它在不同平台上的运行方式也不同。
然而,编译器对此非常满意。
在Python中:
i = 1
++i
print i
输出“1”。行'++i'的计算结果为+(+i) (Python不支持增量操作符)