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

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


当前回答

两个字:多重继承。这毫无意义,只会制造麻烦。

编辑——我指的是c++中的MI,而不是Java和其他语言中的mixins之类的。

其他回答

我有点纠结:

1;

在perl中,模块需要返回true。

在Forth中,任何不包含空格的东西都可以是标识符(包含空格的东西需要做一些工作)。解析器首先检查事物是否定义了,在这种情况下,它被称为单词,如果没有,则检查它是否为数字。没有关键字。

无论如何,这意味着人们可以重新定义一个数字来表示其他东西:

: 0 1 ;

它创建了单词0,由1组成,不管它在执行时是什么。反过来,它会导致以下结果:

0 0 + .
2 Ok

另一方面,定义可以接管解析器本身——这是可以做到的 通过评论词。这意味着Forth程序实际上可以在中途变成一个完全不同语言的程序。事实上,这是Forth推荐的编程方式:首先你写你想要解决问题的语言,然后你解决问题。

在ruby/python/c中,你可以像这样连接字符串:

a = "foo" "bar"
print a # => "foobar"

我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:

void someWindowsFunction() {
    BITMAPINFOHEADER header = {sizeof header};

    /* do stuff with header */
}

这条微妙的线条达到了以下效果:

Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).

在c#中,为什么这是不合法的?

public class MyClass<T>
    where T: Enum
{

}

能够在Enum上添加扩展方法以及Func<T>是非常酷的,其中T将是您正在扩展的Enum,以便您可以对该Enum进行类型推断。

回复评论:是的,你可以扩展一个实际的枚举,但这里有区别:

你可以这样做:

public static void DoSomethingWithEnum(this Enum e)
{
   //do whatever
}

但是如果你想用你的方法获取一个Func,它将是你的enum的相同类型:

public static void DoSomethingWithEnum<T>(this T e, Func<T,bool> func )
   where T: Enum
{
   //do whatever
}

这样,你就可以像这样调用你的方法:

DayOfWeek today = DayOfWeek.Monday;
today.DoSomethingWithEnum(e => e != DayOfWeek.Sunday);

或者类似的东西。你懂的…这是不可能的,我也不知道为什么……