在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
PHP对字符串中数值的处理。详见之前对另一个问题的回答,但简而言之:
"01a4" != "001a4"
如果你有两个包含不同数量字符的字符串,它们不能被认为是相等的。前导零很重要,因为它们是字符串而不是数字。
"01e4" == "001e4"
PHP doesn’t like strings. It’s looking for any excuse it can find to treat your values as numbers. Change the hexadecimal characters in those strings slightly and suddenly PHP decides that these aren’t strings any more, they are numbers in scientific notation (PHP doesn’t care that you used quotes) and they are equivalent because leading zeros are ignored for numbers. To reinforce this point you will find that PHP also evaluates "01e4" == "10000" as true because these are numbers with equivalent values. This is documented behaviour, it’s just not very sensible.
其他回答
在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。这是个很棒的故事。
VBScript中的括号标识符
VBScript有所谓的方括号标识符,这些标识符定义在方括号中,如下所示:
[Foo]
实际上,它们非常方便,因为它们允许您以保留字命名变量和例程,调用第三方对象的方法,其名称是保留字,并且还可以在标识符中使用几乎任何Unicode字符(包括空格和特殊字符)。但这也意味着你可以和他们一起玩:
[2*2] = 5
[Здравствуй, мир!] = [Hello, world!]
[] = "Looks like my name is an empty string, isn't that cool?"
For[For[i=0]=[0]To[To[To[0]
[Next[To]([For[i=0])=[For[i=0]
Next
另一方面,括号标识符可能是一个陷阱,以防你在这样的语句中忘记引号:
If MyString = "[Something]" Then
因为If MyString = [Something] Then是一个完全合法的语法。(这就是为什么必须使用具有语法高亮显示功能的IDE !)
更多关于括号标识符的信息,请参阅Eric Lippert的博客:
VBScript琐事:括号标识符和保留字不兼容 VBScript测试答案,第六部分
Java源文件可以以字符\u001a (control-Z)结尾。
我有点纠结:
1;
在perl中,模块需要返回true。
好吧,既然问题是断断续续的,我就加入到“有趣”中来
Go(又名Issue9)使用大写的可见性:
如果你用大写字母命名某个东西,它就会被公众访问。 如果你使用小写,它将被包保护:
包装外可见:
func Print(v ...) {
}
包外不可见
func print( v ... ) {
}
你可以在这个原始答案中找到更多。