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

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


当前回答

我最喜欢的c++语法小技巧是,你可以把URL(有一些限制)直接放到代码中:

int main( int argc, char *argv[] )
{
    int i=10;

    http://www.stackoverflow.com
    return 1;
}

这可以很好地编译。

语法高亮有点破坏了这个笑话,但它仍然很有趣。

其他回答

大约在1977年,我在Lisp中添加了“format”函数,那时“printf”甚至还不存在(我是从与Unix相同的源:Multics复制的)。它一开始很无辜,但后来被一个接一个的特征填满了。当Guy Steele引入迭代和相关特性时,事情就失控了,这些特性被Common Lisp X3J13 ANSI标准所接受。下面的示例可以在Common Lisp The Language, 2nd Edition第22.3.3节中的表22-8中找到:

(defun print-xapping (xapping stream depth)
  (declare (ignore depth))
  (format stream
      "~:[{~;[~]~:{~S~:[->~S~;~*~]~:^ ~}~:[~; ~]~ ~{~S->~^ ~}~:[~; ~]~[~*~;->~S~;->~*~]~:[}~;]~]"
      (xectorp xapping)
      (do ((vp (xectorp xapping))
           (sp (finite-part-is-xetp xapping))
           (d (xapping-domain xapping) (cdr d))
           (r (xapping-range xapping) (cdr r))
           (z '() (cons (list (if vp (car r) (car d)) (or vp sp) (car r)) z)))
          ((null d) (reverse z)))
      (and (xapping-domain xapping)
           (or (xapping-exceptions xapping)
           (xapping-infinite xapping)))
      (xapping-exceptions xapping)
      (and (xapping-exceptions xapping)
           (xapping-infinite xapping))
      (ecase (xapping-infinite xapping)
        ((nil) 0)
        (:constant 1)
        (:universal 2))
      (xapping-default xapping)
      (xectorp xapping)))

在JavaScript中,2.0 - 1.1 = 0.8999999999999999。这是规范中实现浮点数的结果,所以它总是这样的。

我不敢说XML是一种编程语言,但它不是贴近我们的内心吗?: -)

在我看来,XML中最奇怪的特性是以下是一个格式良好的文档:

<_....>
</_....>

下面是允许连续点的NT-Name的词法定义。

Perl的$[(已弃用),这在之前关于通用Perl变量的另一篇文章中提到过,但它值得特别提到,并有更好的解释。对$[的更改仅限于当前范围。更多的信息以及如何使用它的含义;)可以在$[中找到,请访问http://www.perlmonks.org/index.pl/?node_id=480333

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.