在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
当我在大学的时候,我用一种叫做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代码几乎不可能阅读和理解。”
其他回答
javascript:
parseInt('06'); // 6
parseInt('08'); // 0
我发现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年的结果。
在JavaScript中:
2 == [2]
// Even stranger
2 == [[[2]]]
// And down-right nutty
var a = { "abc" : 1 };
a[[[["abc"]]]] === a["abc"]; // this is also true
幸运的是,stackoverflow.com网站上善良的人们向我解释了这一切: 为什么2 ==[2]在JavaScript?
在c++中,你可以从空指针调用静态方法——看!
class Foo {
public:
static void bar() {
std::cout << "WTF!?" << std::endl;
}
};
int main(void) {
Foo * foo = NULL;
foo->bar(); //=> WTF!?
return 0; // Ok!
}
这句话让我很意外……
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.