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

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


当前回答

ruby中的隐含变量\constants和可变常量

其他回答

Python的三元操作符

在Python中,C三元操作符(c++示例:bool isNegative = i < 0 ?True: false;)可用作语法糖:

>>> i = 1
>>> "It is positive" if i >= 0 else "It is negative!"
'It is positive'
>>> i = -1
>>> "It is positive" if i >= 0 else "It is negative!"
'It is negative!'

这并不奇怪,而是一种特征。奇怪的是,与C中的顺序(条件?答:b)。

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

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

在Common Lisp中,零维数组是很奇怪的,而且很自然地,它们具有读取语法。

? (aref #0A5)
5

在C:

warning C4013: 'myfunc' undefined; assuming extern returning int

我记得由于某些原因没有看到警告(在一些遗留代码中有太多警告?),并且困惑于为什么从int转换会在使用非int返回函数时导致编译器错误。

编译器假设这样的东西是相当出乎意料的。

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

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

然而它可以是:

print "Hello World!"

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