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

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


当前回答

在俄亥俄州立大学,他们用一种叫做Resolve/ c++的杂种c++语言教授编程。Resolve/ c++对一切都使用契约式设计方法。它要求您在编译后的注释中对组件和方法进行数学建模,从而强制您维护方法和对象之间的require /ensure关系。

其他回答

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

COMEFROM是我见过的最奇怪,也可能是最没用的语言功能。

其次是三元运算符,因为它违反了优化的第一条规则。它带来的危害大于它解决的问题。它的危害更大,因为它使代码可读性更差。

并不是一个真正的语言功能,但有趣/很棒的功能使用是Duff的设备。

在Python中:

>>> a[0] = "hello"
NameError: name 'a' is not defined
>>> a[0:] = "hello"
NameError: name 'a' is not defined
>>> a = []
>>> a[0] = "hello"
IndexError: list assignment index out of range
>>> a[0:] = "hello"
>>> a
['h', 'e', 'l', 'l', 'o']

这些切片分配也会给出相同的结果:

a[:] = "hello"
a[42:] = "hello"
a[:33] = "hello"

Perl的许多内置变量:

$# — not a comment! $0, $$, and $? — just like the shell variables by the same name $ˋ, $&, and $' — weird matching variables $" and $, — weird variables for list- and output-field-separators $! — like errno as a number but strerror(errno) as a string $_ — the stealth variable, always used and never seen $#_ — index number of the last subroutine argument... maybe @_ — the (non)names of the current function... maybe $@ — the last-raised exception %:: — the symbol table $:, $^, $~, $-, and $= — something to do with output formats $. and $% — input line number, output page number $/ and $\ — input and output record separators $| — output buffering controller $[ — change your array base from 0-based to 1-based to 42-based: WHEEE! $} — nothing at all, oddly enough! $<, $>, $(, $) — real and effective UIDs and GIDs @ISA — names of current package’s direct superclasses $^T — script start-up time in epoch seconds $^O — current operating system name $^V — what version of Perl this is

还有很多这样的东西。点击这里阅读完整列表。

在Java中从文本文件中读取一行。

BufferedReader in = null;
try {
   in = new BufferedReader(new FileReader("filename"));
   String str;
   str = in.readLine();
   if (str != null) {
      ...
   } 
} catch (IOException e) {
   ...
} finally {
   try {
      if (in != null) {
         in.close();
      }
   } catch (IOException e) {}
}

啊。虽然我承认这并不奇怪……只是邪恶。: -)

更短、更习惯的版本:

try {
   BufferedReader in = new BufferedReader(new FileReader("filename"));
   try {
       String str = in.readLine();
       while (str != null) {
          str = in.readLine();
       } 
    } finally {
        in.close();
    }
} catch (IOException e) {
    e.printStackTrace();
}