在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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.
其他回答
Go的伪常数Iota:
type ByteSize float64
const (
_ = iota; // ignore first value by assigning to blank identifier
KB ByteSize = 1<<(10*iota); MB; GB; TB; PB; YB;
)
在Common Lisp中,零维数组是很奇怪的,而且很自然地,它们具有读取语法。
? (aref #0A5)
5
MySQL枚举,特别是他们的能力,使生活的地狱毫无准备的同事。
CREATE TABLE foo (
....
dispatched ENUM('0','1') NOT NULL DEFAULT '0',
)
然后:
UPDATE TABLE foo SET ..., dispatched = 1;
哎呀,dispatch被设置为0,因为1没有被引用。这真的惹恼了为我编写代码的人;我现在使用普通的int。
在一个相关的注意事项,即使你添加一个空字符串选项到你的枚举,例如。
blah ENUM('','A','B') NOT NULL,
如果给blah赋了一个无效值,MySQL将使用一个秘密隐藏的空字符串值来表示无效值,这将很难与您自己添加的值区分开来。耶!
c# yield语句,并不奇怪,但非常有用。
http://msdn.microsoft.com/en-us/library/9k7k7cf0 (VS.80) . aspx
在Perl中,对象只是被祝福的引用,所以在运行时改变对象的类是小菜一碟:
package Foo;
sub new { bless {}, $_[0] }
package Bar;
package main;
my $foo = Foo->new;
ref($foo); # => "Foo"
bless $foo, 'Bar';
ref($foo); # => "Bar"
我很惊讶其他语言不能做到这一点。多么有用的功能啊!