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

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


当前回答

我所知道的最奇怪的特性来自c++世界:SFINAE。

最糟糕的是,它实际上非常有用,在BOOST中广泛使用SFINAE对我来说已经足够了。

其他回答

Commodore BASIC的命令快捷方式。基本上大多数命令都有一个缩写形式,通常是第一个字母+ (shift+第二个字母)。但是因为C64上的字符集默认都是大写的,这些命令看起来就像奇怪的符号。下面是一个hello world的简短例子:

也许有人有更好的例子,更有实质内容,但对于长程序来说,这看起来完全是荒谬的。

以下是缩略语列表:http://www.c64-wiki.com/index.php/BASIC_keyword_abbreviation

在早期版本的Visual Basic中,没有“Return”语句的函数只是“Return None”,没有任何编译器警告(或错误)。

这导致了最疯狂的调试会话,那时我必须每天处理这种语言。

我喜欢这类东西在JavaScript中很好的事实:

var futureDate = new Date(2010,77,154);
alert(futureDate);

结果是距离2010年第0个月的第0天77个月零154天,即2016年11月1日

在Bash中,变量可以显示为标量和数组:

$ a=3
$ echo $a
3
$ echo ${a[@]}    # treat it like an array
3
$ declare -p a    # but it's not
declare -- a="3"
$ a[1]=4          # treat it like an array
$ echo $a         # acts like it's scalar
3
$ echo ${a[@]}    # but it's not
3 4
$ declare -p a
declare -a a='([0]="3" [1]="4")'
$ a=5             # treat it like a scalar
$ echo $a         # acts like it's scalar
5
$ echo ${a[@]}    # but it's not
5 4
$ declare -p a
declare -a a='([0]="5" [1]="4")'

KSH做同样的事情,但是使用排版而不是声明。

当你在zsh中这样做时,你得到的是子字符串赋值而不是数组:

$ a=3
$ a[2]=4          # zsh is one-indexed by default
$ echo $a
34
$ a[3]=567
$ echo $a
34567
$ a[3]=9
$ echo $a
34967
$ a[3]=123         # here it overwrites the first character, but inserts the others
$ echo $a
3412367
$ a=(1 2 3)
$ echo $a
1 2 3              # it's an array without needing to use ${a[@]} (but it will work)
$ a[2]=99          # what about assignments?
$ echo $a
1 99 3

回想起来,FORTRAN的计算goto是相当奇怪的。维基百科告诉我一些基础知识胜过它。

另一个著名的最爱是Algol 60的名称参数调用传递。