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

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


当前回答

在php中:

easter_date -获取给定年份复活节午夜的Unix时间戳

Int easter_date ([Int $year])

其他回答

X = X + 1

当我还是初学者的时候,这很难消化,而现在函数式语言不使用它了,这就更难了!

如果你不明白这有多奇怪:把等号看作断言语句,而不是赋值操作,就像你在基础代数中经常做的那样,那么这相当于说“0 = 1”。

INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.

在Java中:

int[] numbers() {
  return null;
}

可以写成:

int numbers() [] {
  return null;
}

对于那些不知道的人,bc是一种“任意精度计算器语言”,我经常使用它进行快速计算,特别是当涉及的数字很大的时候($是提示符):

$ bc -lq
12^345
20774466823273785598434446955827049735727869127052322369317059031795\
19704325276892191015329301807037794598378537132233994613616420526484\
93077727371807711237016056649272805971389591721704273857856298577322\
13812114239610682963085721433938547031679267799296826048444696211521\
30457090778409728703018428147734622401526422774317612081074841839507\
864189781700150115308454681772032

bc在很长一段时间内都是标准的Unix命令。

现在是“WTF功能”。这是来自man bc(强调是我的):

quit:当读取quit语句时,bc处理器被终止, 不管在哪里找到quit语句。 例如,"if (0 == 1) quit"将导致bc终止。 halt: halt语句(扩展)是一个执行的语句 导致BC处理器仅在执行时退出。 例如,"if (0 == 1) halt"不会导致bc终止,因为停止没有执行。

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

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

然而它可以是:

print "Hello World!"

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