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

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


当前回答

好吧,既然问题是断断续续的,我就加入到“有趣”中来

Go(又名Issue9)使用大写的可见性:

如果你用大写字母命名某个东西,它就会被公众访问。 如果你使用小写,它将被包保护:

包装外可见:

func Print(v ...) { 
}

包外不可见

func print( v ... ) {
}

你可以在这个原始答案中找到更多。

其他回答

在C。

int;

(&a)[0] = 10;/*将值10赋给*/

[0]等于*(&a +0)得到*(&a)也就是a。

不久前,当我在CS课上第一次发现C语言时,看到指针的行为方式是非常奇怪的。我们只是编写程序并猜测它会做什么,直到它们得到正确的行为

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八进制转换“特性”是一个很好的了解:

parseInt('06') // 6
parseInt('07') // 7
parseInt('08') // 0
parseInt('09') // 0
parseInt('10') // 10

详情请点击这里。

在c++

const char* wtf()
{
    char buf[100];
    return buf;
}
string s = ... + wtf() + ...;

在s中创建有趣的值。部分是字符串,部分是堆栈内容,与零混合,因此s.length()!=strlen(s.c_str())。 最奇怪的是,编译器在返回指向堆栈的指针时完全没有问题——如果他在那里添加了一个警告,编译器程序员的手可能会掉下来。