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

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


当前回答

一般来说,弱类型。

C:

printf("%c\n", 'a' + 3);

PHP:

echo 5 + "3";

还有太多其他语言。

其他回答

Perl:

可以编写一个完全由标点符号组成的程序。

这是怎么回事?!

哈哈!

整个语言本身。虽然不完全是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

Haskell's use of Maybe and Just. Maybe a is a type constructor that returns a type of Just a, but Maybe Int won't accept just an Int, it requires it to be a Just Int or Nothing. So in essence in haskell parlance Just Int is about as much of an Int as an apple is an orange. The only connection is that Just 5 returns a type of Maybe Interger, which can be constructed with the function Just and an Integer argument. This makes sense but is about as hard to explain as it can theoretically be, which is the purpose of haskell right? So is Just really JustKindaLikeButNotAtAll yea sorta, and is Maybe really a KindaLooksLikeOrIsNothing, yea sorta again.

-- Create a function that returns a Maybe Int, and return a 5, which know is definitly Int'able
>  let x :: Maybe Int; x = 5;
<interactive>:1:24:
    No instance for (Num (Maybe Int))
      arising from the literal `5' at <interactive>:1:24
    Possible fix: add an instance declaration for (Num (Maybe Int))
    In the expression: 5
    In the definition of `x': x = 5

>  Just 5  
Just 5
it :: Maybe Integer

    -- Create a function x which takes an Int
>  let x :: Int -> Int; x _ = 0;
x :: Int -> Int
-- Try to give it a Just Int
>  x $ Just 5                   

<interactive>:1:4:
    Couldn't match expected type `Int' against inferred type `Maybe t'
    In the second argument of `($)', namely `Just 5'
    In the expression: x $ Just 5
    In the definition of `it': it = x $ Just 5

祝你好运读到这篇文章,我希望它是正确的。

在JavaScript中,方法的结果取决于所放置的样式花括号。这是K&R风格,其中括号放在方法签名之后和return语句之后:

var foo = function() {
  return {
    key: 'value'
  };
}

foo() // returns an object here

现在,如果我将这段代码格式化为Allman风格,其中括号总是放在新行上,结果是不同的:

var foo = function()
{
  return
  {
    key: 'value'
  };
}

foo() // returns undefined here

如何来吗?在JavaScript中,如果您不自己做,语言会自动在每行末尾放置分号。所以在最后一个代码片段中真正发生的是这样的:

var foo = function()
{
  return; // here's actually a semicolon, automatically set by JavaScript!
  {
    key: 'value'
  };
}

因此,如果调用foo(),方法中的第一个语句将是一个返回语句,该语句将返回undefined,并且不会执行后面的其他语句。

Fortran中不同列的特殊含义。(如果你从小就有穿孔卡片,这可能是很自然的。)

这样做的一个副作用是,例如变量名在第72列之后被截断。结合隐式NONE,当这样的变量名在第72列附近开始时,它会无声地引入一个新变量。

你需要

要知道这一点 以不同的方式高亮显示注释部分(第72列之后)的编辑器 颜色比之前的部分…