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

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


当前回答

A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.

其他回答

NSIS (Nullsoft Scriptable安装系统)有StrCmp指令:

StrCmp str1 str2 jump_if_equal [jump_if_not_equal] 比较str1和str2(不区分大小写)。如果str1和str2相等,则Gotos jump_if_equal,否则Gotos jump_if_not_equal。 StrCmp $0“一个字符串”0 +3 DetailPrint '$$0 == "a string"' 转到+ 2 DetailPrint '$$0 != "a string"'

锦上添花:jump_if_equal和jump_if_not_equal也可以是负数。但我猜你们已经从正数前面的+符号中算出来了。我不记得这是强制性的,还是只是一个可怕的惯例。

这基本上结合了最差的BASIC和最差的Assembler。

试试吧,除非,否则

try:     pass
except:  pass
else:    pass
finally: pass

如果没有捕获异常,则执行else部分。

有道理,但一开始我真的不知道它是干什么的。

例子:

def show_square(string):
  try:
    n = int(string, 10)
  except ValueError:
    print "I can't do that, Dave."
  else:
    print n * n

另一个C-ism。

int i= 0;
while( i != 12 ) {
    /* Some comment 
    i += 1;
    /* Another comment */
}

为什么不行?棉绒会告诉你。然而,C编译器通常会轻松地忽略这一点。我也是。

当我发现问题出在哪里的时候,那真是太棒了。

Algol通过名称传递(使用C语法说明):

int a[3] = { 1, 2, 3 };
int i = 1;

void f(int j)
{
    int k;
    k = j;  // k = 2
    i = 0;
    k = j;  // k = 1 (!?!)    
}

int main()
{
    f(a[i]);
}

在c#中,这至少应该生成一个编译器警告,但它没有:

public int Something
{
    get { return Something; }
    set { Something = value; }
}

当被调用时,它会导致你的应用程序崩溃,你不会得到一个好的堆栈跟踪,因为它是一个StackOverflowException。