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

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


当前回答

这并不是说它被大量使用,而是c++的“返回对静态大小数组的引用”的语法很奇怪:

struct SuperFoo {
  int (&getFoo() const)[10] {
    static int foo[10];
    return foo;
  }
}

在上述情况下,Ofc方法可以声明为静态const

其他回答

哈哈!

整个语言本身。虽然不完全是WTF的事情,但我从来没有遇到过一种语言在我的脑海中以一种刺耳的卡通声音播放。我以前也从来没有看过代码并想要惊呼“啊啊啊啊可爱!”

这个程序显示数字1-10并终止

HAI
CAN HAS STDIO?
IM IN YR LOOP UPPIN YR VAR TIL BOTHSAEM VAR AN 10
    VISIBLE SUM OF VAR AN 1
IM OUTTA YR LOOP
KTHXBYE

一些早期的动态语言(包括,如果我没记错的话,Perl的早期版本)没有弄清楚什么是好的动态,什么是坏的动态。所以他们中的一些人允许这样做:

1 = 2;

在这句话之后,下列情况是正确的:

if(1 + 1 == 4)

在Ruby中,你可以用heredocs做一些奇怪的事情。考虑:

a = <<ONE
This is one. #{<<TWO}
This is two. #{<<THREE}
This is three.
THREE
TWO
ONE

p a # => "This is one. This is two. This is three.\n\n\n"

在J中,foreign(!:)是各种函数组合在一起。左边的参数是一个类别,右边的参数通常(但不总是)是不同的增量值。的东西。例如:

    2!:55 NB. Close console
    9!:10 NB. Set print precision
    6!:0  NB. Actual time
    6!:2  NB. Execution time
    4!:3  NB. Loaded scripts

当然,聪明的做法是把它们包装起来,但有些你只需要记住。顺便说一句,所有这些都是,想想看,三位一体的,有两个参数在右边,一个在左边。除非你给他们一个最终有效的论据,否则以上任何一条都不会起作用。

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.