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

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


当前回答

在Python中,至少对我来说,这是非常wft的!我第一次看的时候:

>>> "ja " * 5
'ja ja ja ja ja '

你可以将字符串相乘!WTF ? ?

PS:我认为这是因为x * n意味着:n乘以x,所以,5次“ja”是“ja”“ja”“ja”“ja”“ja”“ja”,因为你可以像这样连接字符串:

>>> "ja ""ja ""ja ""ja ""ja "
'ja ja ja ja ja '

两个代码有相同的结果(可能是相同的)

其他回答

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

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

Delphi不关心像“word”这样的类型转换,将读取数组arr[0..65535] where pos = 65535: Arr[单词(pos + 10)]

我一直在想为什么最简单的程序是:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

然而它可以是:

print "Hello World!"

也许这是为了吓唬计算机科学专业的学生……

我想说的是,Python的空白是我最棒的WTF特性。的确,你或多或少会在一段时间后习惯它,而且现代编辑器使它更容易处理,但即使在过去一年里我几乎全职从事python开发,我仍然相信这是一个坏主意。我已经阅读了所有背后的原因,但说实话,它妨碍了我的工作效率。差不了太多,但鞍下还是有毛刺。

编辑:从评论来看,有些人似乎认为我不喜欢缩进我的代码。这是一个不正确的评估。无论使用什么语言,无论是否被迫,我总是将代码缩进。我不喜欢的是,缩进定义了一行代码所在的块。我更喜欢使用显式分隔符。除其他原因外,我发现显式分隔符更容易剪切和粘贴代码。

例如,如果我有一个缩进4个空格的块,并将它粘贴到一个缩进8个空格的块的末尾,我的编辑器(所有编辑器?)不知道粘贴的代码是属于8个空格的块还是外部块。OTOH,如果我有显式分隔符,很明显,代码属于哪个块以及它应该如何(重新)缩进——它通过智能地寻找块分隔符来做到这一点。

编辑2:一些提供评论的人似乎认为这是一个我讨厌的功能,或者我认为这使得python成为一种糟糕的语言。同样,这不是真的。虽然我不太喜欢它,但这不是重点。这个问题是关于最奇怪的语言特征,我认为这很奇怪,因为它是非常非常少(但是>0)语言使用的东西。

在MySQL中字符串比较是不区分大小写的。

> SELECT * FROM blah WHERE foo = 'BAR';
> SELECT * FROM blah WHERE foo = 'Bar';
> SELECT * FROM blah WHERE foo = 'bAr';

都是等价的。它们不仅会匹配任何看起来像'bar'的foo值(例如,如果foo = 'bar',它将匹配bar, bar, bar等)。