在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
腮腺炎。WTF有很多特性,我选了一个if语句。(请注意,我在下面使用了一种相当冗长的编码风格,以适应那些不懂这门语言的人;真正的腮腺炎代码通常对外行来说更难以理解。)
if x>10 do myTag(x) ; in MUMPS "tag" means procedure/function
else do otherTag(x)
这类似于Java中的说法:
if (x > 10) {
myMethod(x);
} else {
otherMethod(x);
}
除了在MUMPS中,else语句在语法上不是if块的一部分,它是一个单独的语句,通过检查内置变量$TEST来工作。每次执行if语句时,它都会将$TEST设置为if语句的结果。else语句实际上意味着“如果$TEST为假,则执行该行剩余部分,否则跳转到下一行”。
这意味着如果x大于10,因此第一行叫做myTag,并且myTag包含if语句,那么else的行为不取决于它上面一行的if,而是取决于myTag内部的最后一个if !由于这个“特征”,MUMPS编码员通常被教导像这样编写以上代码以确保安全:
if x>10 do myTag(x) if 1
else do otherTag(x)
第一行末尾的if 1确保在控制进行到下一行之前正确地设置了$TEST。(顺便说一下,这里的间距必须是这样的,在else后面有两个空格,在所有其他地方都有一个空格。间距是奇怪的,但至少一旦你理解了模式,它是非常正交的。)
其他回答
Perl中的字符串数学非常奇怪。
$ perl -E '$string = "a"; $string++; say $string'
b
$ perl -E '$string = "abc"; $string++; say $string'
abd
$ perl -E '$string = "money"; $string++; say $string'
monez
$ perl -E '$string = "money"; $string--; say $string'
-1
Powerbasic (www.powerbasic.com)包含编译器指令:
# BLOAT {bloatsize}
这将使编译后的可执行文件的大小增加<bloatsize>字节。这是放在编译器中,以防创建可执行文件的人不喜欢生成的可执行文件的小尺寸。它使EXE看起来更大,以与臃肿的编程语言竞争:)
Java有一整本关于它们的书。
书http://www.javapuzzlers.com/lg-puzzlers-cropped.jpg
爪哇益智游戏
一个意想不到的特性是,在C、c#、Ruby等语言中,枚举定义列表和数组初始化列表中的末尾逗号。
string[] foods = { "tofu", "grits", "cabbage", }
public enum ArtPeriod {
Modern,
Romantic,
Dada,
}
在fortran中(当然是77,可能在95中也是如此),未声明的变量和以I到N开头的参数(“In”组)将是INTEGER,所有其他未声明的变量和参数将是REAL(源)。这与“在某些情况下可选的空白”相结合,导致了最著名的错误之一。
正如弗雷德·韦伯在1990年的《另类民间传说:计算机》一书中所说:
I worked at Nasa during the summer of 1963. The group I was working in was doing preliminary work on the Mission Control Center computer systems and programs. My office mate had the job of testing out an orbit computation program which had been used during the Mercury flights. Running some test data with known answers through it, he was getting answers that were close, but not accurate enough. So, he started looking for numerical problems in the algorithm, checking to make sure his tests data was really correct, etc. After a couple of weeks with no results, he came across a DO statement, in the form: DO 10 I=1.10 This statement was interpreted by the compiler (correctly) as: DO10I = 1.10 The programmer had clearly intended: DO 10 I = 1, 10 After changing the . to a , the program results were correct to the desired accuracy. Apparently, the program's answers had been "good enough" for the sub-orbital Mercury flights, so no one suspected a bug until they tried to get greater accuracy, in anticipation of later orbital and moon flights. As far as I know, this particular bug was never blamed for any actual failure of a space flight, but the other details here seem close enough that I'm sure this incident is the source of the DO story.
我认为这是一个很大的WTF,如果DO10I被作为DO10I,并且反过来,因为隐式声明被认为是类型REAL。这是个很棒的故事。