在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
早期的FORTRAN,空格不重要。(anti-Python !)
DO 20 I = 1, 10
含义:从这里循环到第20行,I从1到10。
DO 20 I = 1. 10
含义:将1.10分配给名为DO20I的变量。
有传言说这个漏洞毁了一个太空探测器。
其他回答
在JavaScript中,void不是关键字,不是类型声明,也不是变量名,也不是函数,也不是对象。Void是一个前缀操作符,类似于-、——、++和!你可以给任何表达式加上前缀,这个表达式的值将是undefined。
它经常被用在bookmarklet和内联事件处理程序中,比如下面这个比较常见的例子:
<a href="javascript:void(0)">do nothing</a>
在这个例子中使用它的方式使它看起来像一个函数调用,而实际上它只是一种获得原始未定义值的过于聪明的方法。大多数人并没有真正理解JavaScript中void的真正本质,这可能会导致许多讨厌的bug和奇怪的意想不到的事情发生。
不幸的是,我认为void操作符是在JavaScript中获得未定义值的唯一真正保证的方法,因为未定义,正如在另一个回答中指出的,是一个可以重新赋值的变量名,而{}。a可以被Object.prototype.a = 'foo'打乱
更新:我想到了另一种生成undefined的方法:
(function(){}())
嗯,有点啰嗦,返回“undefined”是它的目的就更不清楚了。
Perl充满了奇怪但整洁的特性。
If可以用在语句之前或之后,就像这样:
print "Hello World" if $a > 1;
if ($a > 1) { print "Hello World"; }
foreach也是如此:
print "Hello $_!\n" foreach qw(world Dolly nurse);
Oracle有几个SQL WTF问题。
Oracle将空字符串处理为null。 在“<>”比较中处理空值。 创建表WTF(键数为主键,动物varchar2(10)); 插入WTF值(1,'dog'); Insert into WTF values (2, "); Insert into WTF values (3,'cat'); Select * from WTF where animal <> 'cat';
唯一返回的行是(1,'dog')行。
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.
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.