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

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


当前回答

学习PowerShell时发现:

试着猜一下结果数组是什么样的:

$a = 1, 2
$b = 1, 2+3
$c = 1, 2*3

答案:

1, 2
1, 2, 3
1, 2, 1, 2, 1, 2

哎哟!它动摇了我对PowerShell及其开发人员的信心。

其他回答

Duff的C语言设备!

在C语言中,可以将do/while语句与switch语句交错使用。下面是memcpy使用此方法的示例:

void duff_memcpy( char* to, char* from, size_t count ) {
    size_t n = (count+7)/8;
    switch( count%8 ) {
    case 0: do{ *to++ = *from++;
    case 7:     *to++ = *from++;
    case 6:     *to++ = *from++;
    case 5:     *to++ = *from++;
    case 4:     *to++ = *from++;
    case 3:     *to++ = *from++;
    case 2:     *to++ = *from++;
    case 1:     *to++ = *from++;
            }while(--n>0);
    }
}

我最喜欢的奇怪的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).

我很惊讶居然没有人提到Visual Basic的7个循环结构。

For i As Integer = 1 to 10 ... Next
While True ... End While
Do While True ... Loop
Do Until True ... Loop
Do ... Loop While True
Do ... Loop Until True
While True ... Wend

因为粘!你面前的条件实在是太复杂了!

因为我还没见过任何人提起它……RPG 2或3(报告程序生成器…又名火箭推进垃圾)是迄今为止我用过的最疯狂的语言。它几乎没有对程序流的控制(在文件顶部的Enter,在底部的Exit),并且编程语句是基于使用固定字体在特定列中定义的字符定义的(想想PUNCH CARDS!!)

要真正做到FUBAR,你必须尝试用DYL-280编程。它将RPG流程和逻辑与COBOL语法结合在一起。

在这里查找RPG: wikipedia.org /wiki/IBM_RPG

DYL-280的示例:http://99-bottles-of-beer.net/language-dyl-280-224.html

VBScript的日期/时间文字(为什么这个仍然如此罕见?):

mydate = #1/2/2010 5:23 PM#

If mydate > #1/1/2010 17:00# Then ' ...

编辑:日期文字是相对的(那么它们在技术上是文字吗?):

mydate = #Jan 3# ' Jan 3 of the current year

VB。NET,因为它是编译的,所以不支持相对日期文字。只支持日期或时间字面量,但缺失的时间或日期被假定为零。

编辑[2]:当然,有一些奇怪的极端情况会出现相对日期……

mydate = #Feb 29# ' executed on 2010-01-05, yields 2/1/2029