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

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


当前回答

一些早期的动态语言(包括,如果我没记错的话,Perl的早期版本)没有弄清楚什么是好的动态,什么是坏的动态。所以他们中的一些人允许这样做:

1 = 2;

在这句话之后,下列情况是正确的:

if(1 + 1 == 4)

其他回答

腮腺炎。WTF有很多特性,我选了一个if语句。(请注意,我在下面使用了一种相当冗长的编码风格,以适应那些不懂这门语言的人;真正的腮腺炎代码通常对外行来说更难以理解。)

if x>10 do myTag(x)    ; in MUMPS "tag" means procedure/function
else  do otherTag(x)

这类似于Java中的说法:

if (x > 10) {
  myMethod(x);
} else {
  otherMethod(x);
}

除了在MUMPS中,else语句在语法上不是if块的一部分,它是一个单独的语句,通过检查内置变量$TEST来工作。每次执行if语句时,它都会将$TEST设置为if语句的结果。else语句实际上意味着“如果$TEST为假,则执行该行剩余部分,否则跳转到下一行”。

这意味着如果x大于10,因此第一行叫做myTag,并且myTag包含if语句,那么else的行为不取决于它上面一行的if,而是取决于myTag内部的最后一个if !由于这个“特征”,MUMPS编码员通常被教导像这样编写以上代码以确保安全:

if x>10 do myTag(x) if 1
else  do otherTag(x)

第一行末尾的if 1确保在控制进行到下一行之前正确地设置了$TEST。(顺便说一下,这里的间距必须是这样的,在else后面有两个空格,在所有其他地方都有一个空格。间距是奇怪的,但至少一旦你理解了模式,它是非常正交的。)

我发现Javascript Date Object对110年的热爱令人愉快。 试一试。

<Script language ="JavaScript">
<!--
var now = new Date()
var dia = now.getDay()
var mes = now.getMonth()
var fecha

//Day of the week
if(dia==0){
 fecha="Domingo, ";
}else if(dia==1){
 fecha="Lunes, ";
}else if(dia==2){
 fecha="Martes, ";
}else if(dia==3){
 fecha="Miércoles, ";
}else if(dia==4){
 fecha="Jueves, ";
}else if(dia==5){
 fecha="Viernes, ";
}else{
 fecha="Sábado, ";
}

fecha = fecha + now.getDate() + " de "
//Which month is it?
if(mes==0){
 fecha=fecha + "Enero"
}else if(mes==1){
 fecha=fecha + "Febrero"
}else if(mes==2){
 fecha=fecha + "Marzo"
}else if(mes==3){
 fecha=fecha + "Abril"
}else if(mes==4){
 fecha=fecha + "Mayo"
}else if(mes==5){
 fecha=fecha + "Junio"
}else if(mes==6){
 fecha=fecha + "Julio"
}else if(mes==7){
 fecha=fecha + "Agosto"
}else if(mes==8){
 fecha=fecha + "Septiembre"
}else if(mes==9){
 fecha=fecha + "Octubre"
}else if(mes==10){
 fecha=fecha + "Noviembre"
}else{
 fecha=fecha + "Diciembre"
}

//Year
fecha = fecha + " del " + now.getYear()

document.write(fecha);
//-->
</Script>

脚本是西班牙语-抱歉如果你不明白代码..这个想法是为了让你看到110年的结果。

PHP对字符串中数值的处理。详见之前对另一个问题的回答,但简而言之:

"01a4" != "001a4"

如果你有两个包含不同数量字符的字符串,它们不能被认为是相等的。前导零很重要,因为它们是字符串而不是数字。

"01e4" == "001e4"

PHP doesn’t like strings. It’s looking for any excuse it can find to treat your values as numbers. Change the hexadecimal characters in those strings slightly and suddenly PHP decides that these aren’t strings any more, they are numbers in scientific notation (PHP doesn’t care that you used quotes) and they are equivalent because leading zeros are ignored for numbers. To reinforce this point you will find that PHP also evaluates "01e4" == "10000" as true because these are numbers with equivalent values. This is documented behaviour, it’s just not very sensible.

APL(除了ALL),在一行中编写任何程序的能力。

例:在APL中,康威的生命游戏一行:

替代文本 http://catpad.net/michael/APLLife.gif

如果这句台词都不是WTF,那什么都不是!

这是一个视频

当今所有语言:

TypeA a = (TypeA)some_operation_returning_TypeB(1,2,3); // TypeB is not inheriting TypeA

在运行时失败,并带有"Cast to TypeA failed exception"-消息(或类似消息)。这告诉我们程序员到底有多懒。他们没有办法产生消息“未能将TypeA的变量‘a’与TypeB的值‘some_operation_returning_TypeB(1,2,3)’赋值”。他. .他们的座右铭是“犯错误的人必须受苦”。