在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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.
其他回答
好吧,既然问题是断断续续的,我就加入到“有趣”中来
Go(又名Issue9)使用大写的可见性:
如果你用大写字母命名某个东西,它就会被公众访问。 如果你使用小写,它将被包保护:
包装外可见:
func Print(v ...) {
}
包外不可见
func print( v ... ) {
}
你可以在这个原始答案中找到更多。
在ColdFusion
Struct(又名Java HashMap)是通过引用传递的。
你可能认为其他数据类型的行为就像Java…
数组是按值传递的,wtf!
List只是一个普通的逗号分隔的字符串!
我几年前使用的一个Fortran编译器有一个有趣的特性:(A)数字先存储在高字节;(b)数字按地址传递给子程序;(c)没有在编译时检查长度。
所以你可以写一个这样的程序:(如果我把语法弄乱了,请原谅。我已经很久没有写Fortran了。)
INTEGER*2 FUNCTION TIMESTWO (INTEGER*2 N)
RETURN N*2
... THEN CALL THIS SOMEWHERE WITH A LONG INTEGER ...
INTEGER*4 I, J
I=42
J=TIMESTWO(I)
J的最终值是…零!
为什么?因为传入的值是4个字节,但被调用的函数只查看前两个字节。由于前两个是0,它将0乘以2并返回它。然后将此返回值转换回四个字节。
当我第一次遇到它时,它非常神秘。几乎我传递给某些函数的每个数字都被解释为零!
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
在Java中可以抛出任何可抛出的东西。
class YourBoss extends Throwable {
}
public class Main{
public void main(String[] s) throws YourBoss {
try{
throw new YourBoss();
}catch(Exception e){
}catch(Error e){
}
}
}