在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
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.
其他回答
在C或c++中,sizeof…参数的圆括号是可选的。假设参数不是类型:
void foo() {
int int_inst;
// usual style - brackets ...
size_t a = sizeof(int);
size_t b = sizeof(int_inst);
size_t c = sizeof(99);
// but ...
size_t d = sizeof int_inst; // this is ok
// size_t e = sizeof int; // this is NOT ok
size_t f = sizeof 99; // this is also ok
}
我一直不明白这是为什么!
Perl充满了奇怪但整洁的特性。
If可以用在语句之前或之后,就像这样:
print "Hello World" if $a > 1;
if ($a > 1) { print "Hello World"; }
foreach也是如此:
print "Hello $_!\n" foreach qw(world Dolly nurse);
大约20年前,当我最后一次涉足腮腺炎时,实现有一些奇怪的局限性。当主机MUMPS变得越来越流行时,MUMPS传统上是一种自托管语言:计算机语言、操作系统和数据库在一个包中。
腮腺炎主要是关于它的数据库。本质上,这是一个巨大的多维哈希表,由B*树支持,可以快速访问。语言和数据库之间也没有任何障碍:如果您想在那里存储一些东西,只需在变量前面加上一个符号,表明它将被持久化到备份存储中。
另一方面,文件系统几乎不存在,对它的支持就更少了。我们唯一能做的就是把一个程序从文件中加载到内存中,然后把内存中的内容发送回文件。最好在加载前清空缓冲区,否则它会和之前的东西混在一起。
因此,考虑到它的自托管性质和极其恶劣的文件系统,人们可能会想知道这些程序是如何编辑的。事实上,编辑器是用MUMPS本身编写的——那么,编辑器如何在不重写自己的情况下将程序存储在内存中呢?
好吧,诀窍在于能够以源代码的形式执行变量的内容。然后,编辑器将自己加载到变量中,在变量中执行自己,清除内存,然后在内存中加载、保存和编辑文件,一直从变量中执行。
除此之外,所有命令都可以被缩短为它们的第一个字母(除了Z命令,缩短为两个字母,主要处理文件系统),还有一个奇怪的事实,比如IF (I)设置了一个变量,然后由ELSE (E)查询——当然,可以被任何介入的I或程序本身覆盖。转念一想,我觉得整个语言就是个垃圾。然而,它有一种奇怪的吸引力。
我很惊讶居然没有人提到Visual Basic的7个循环结构。
For i As Integer = 1 to 10 ... Next
While True ... End While
Do While True ... Loop
Do Until True ... Loop
Do ... Loop While True
Do ... Loop Until True
While True ... Wend
因为粘!你面前的条件实在是太复杂了!
Java有一整本关于它们的书。
书http://www.javapuzzlers.com/lg-puzzlers-cropped.jpg
爪哇益智游戏