在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Perl中,可以通过修改一个类的@ISA数组来改变它的继承链,这让我很惊讶。
package Employee;
our @ISA = qw(Person);
# somwhere far far away in a package long ago
@Employee::ISA = qw(Shape);
# Now all Employee objects no longer inherit from 'Person' but from 'Shape'
其他回答
我有点纠结:
1;
在perl中,模块需要返回true。
Java的访问修饰符对我来说是最近的一个WTF(因为我必须学习一点)。
显然,包比类层次结构更亲密。我不能定义对子类可见但对包中的其他类不可见的方法和属性。为什么我要将一个类的内部共享给其他类呢?
但是我可以定义对包内的每个类可见的属性和方法,但对包外的子类不可见。
不管我怎么想,我还是看不出其中的逻辑。切换访问修饰符,使受保护的行为就像它在c++中工作一样,并保持包的私有修饰符,这是有意义的。但现在不是了。
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.
In C
a[i++] = i;
它会编译,但很少执行您认为它应该执行的操作。优化更改会产生截然不同的结果。它在不同平台上的运行方式也不同。
然而,编译器对此非常满意。
ANSI SQL中空值的三值逻辑。