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

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


当前回答

在c#中,以下代码会生成编译器错误“无法从方法组转换为委托”。虽然背后的逻辑是合理的,但我还是觉得很奇怪。

control.BeginInvoke(delegate { DoSomething(); });

其他回答

我很惊讶没有人提到大多数类c语言中丑陋的开关case实现

switch (someInt) {
    case 1:
    case 2: System.out.println("Forgot a break, idiot!");
    case 3: System.out.println("Now you're doing the wrong thing and maybe need hours to find the missing break muahahahaha");
            break;
    default: System.out.println("This should never happen -,-");        
}

好在新语言正确地实现了它。

C# has a feature called "extension methods", which are roughly analogous to Ruby mix-ins - Essentially, you can add a method to any pre-existing class definition (for instance, you oould add "reverse()" to String if you were so inclined). That alone is fine- The "Weird" part is that you can add these extension methods, with a method body and everything, to an interface. On the one hand, this can be handy as a way to add a single method to a whole swath of classes which aren't part of the same inheritance tree. On the other, you're adding fleshed out methods to interfaces, essentially breaking the very definition of an interface.

这并不奇怪或令人惊讶,但这让我总是说WTF:

语法或标识符名称的大小写敏感性。

大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。

当我在大学的时候,我用一种叫做SNOBOL的语言做了一点工作。整个语言虽然很酷,但却是一个大WTF。

它的语法是我见过的最奇怪的。而不是GoTo,你使用:(标签)。当你有:S(label)(成功/true时的goto标签)和:F(label)(失败/false时的goto标签)并且你在一行中使用这些函数检查某些条件或读取文件时,谁还需要if呢?所以这个表述是:

H = INPUT :F(end)

将从文件或控制台读取下一行,如果读取失败(因为到达EOF或任何其他原因),将转到标签“end”。

然后是$ sign操作符。它将使用变量中的值作为变量名。所以:

ANIMAL = 'DOG'
DOG = 'BARK'
output = $ANIMAL

将在控制台上显示'BARK'值。因为这还不够奇怪:

$DOG = 'SOUND'

将创建一个名为BARK的变量(参见上面分配给DOG的值),并赋予它一个“SOUND”的值。

你看得越多,情况就越糟。我所发现的关于SNOBOL的最好的陈述(来自链接文本)是“该语言的强大功能及其相当惯用的控制流特性使得编写后的SNOBOL4代码几乎不可能阅读和理解。”

英语中的虚拟语气。

等等,你是说编程语言吗?然后在C中使用(宏)绕过宏()的预处理器#定义。例如,如果有人使用#define free(…),(free)(…)将与free(…)不同。