在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
我很惊讶没有人提到大多数类c语言中丑陋的开关case实现
switch (someInt) {
case 1:
case 2: System.out.println("Forgot a break, idiot!");
case 3: System.out.println("Now you're doing the wrong thing and maybe need hours to find the missing break muahahahaha");
break;
default: System.out.println("This should never happen -,-");
}
好在新语言正确地实现了它。
其他回答
英语中的虚拟语气。
等等,你是说编程语言吗?然后在C中使用(宏)绕过宏()的预处理器#定义。例如,如果有人使用#define free(…),(free)(…)将与free(…)不同。
在Python中:
i = 1
++i
print i
输出“1”。行'++i'的计算结果为+(+i) (Python不支持增量操作符)
A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.
在php中:
easter_date -获取给定年份复活节午夜的Unix时间戳
Int easter_date ([Int $year])
闲聊:
在类Test中有一个类方法,返回一个常量字符串:
method1
^ 'niko'
无论发生什么,这个方法都会不断返回字符串'niko'。但事实并非如此。
s := Test method1
(设置为“niko”。)
s at: 4 put: $i.
(设置为“niki”。)
s := Test method1
(再次设置为“niki”。)
因此,第二行代码永久地将method1更改为返回'niki'而不是'niko',即使方法的源代码没有更新。