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

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


当前回答

我发现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年的结果。

其他回答

我一直在想为什么最简单的程序是:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

然而它可以是:

print "Hello World!"

也许这是为了吓唬计算机科学专业的学生……

我一直是PHP错误的忠实粉丝,当在一行中使用两个冒号时脱离上下文:

解析错误:语法错误,第3行/path/to/file/error.php中的T_PAAMAYIM_NEKUDOTAYIM异常

第一次遇到这种情况时,我完全被弄糊涂了。

Python的everything-is-really-a-reference有一个有趣的副作用:

>>> a = [[1]] * 7
>>> a
[[1], [1], [1], [1], [1], [1], [1]]
>>> a[0][0] = 2
>>> a
[[2], [2], [2], [2], [2], [2], [2]]

JavaScript日期全是WTF。

var d = new Date("1/1/2001");

var wtfyear = d.getYear(); // 101 (the year - 1900)
// to get the *actual* year, use d.getFullYear()

var wtfmonth = d.getMonth(); // 0
// months are 0-based!

有向图和替代标记

C (ISO/IEC 9899:1999, 6.4.6/3)和c++ (ISO/IEC 14882:2003, 2.5)有一个很少使用的特性,被C称为“有向图”,被c++称为“替代令牌”。它们不同于三trigraph,主要是因为包含它们的字符串字面量永远不会被不同地解释。

%:include <stdio.h>

int main() <%
    int a<:10:> = <%0%>;
    printf("Here's the 5th element of 'a': %d\n", a<:4:>);
    puts("Evil, eh? %:>");
    return 0;
%>

c++有更多,包括and, or, and not,它们被要求表现为&&,||和!C语言也有这些,但是需要包含<iso646.h>来使用它们,将它们视为宏而不是令牌。c++头文件<ciso646>实际上是一个空文件。

值得注意的是,GCC实现了对这种奇怪的语言特性的支持,但许多其他编译器在尝试编译上述代码段时都阻塞并死亡。