在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

c#的默认继承模型赢得了我的投票:

public class Animal
{
    public string Speak() { return "unknown sound" ; }
}

public class Dog : Animal
{
    public string Speak() { return "Woof!" ; }
}

class Program
{
    static void Main( string[] args )
    {
        Dog aDog = new Dog() ;
        Animal anAnimal = (Animal) aDog ;

        Console.WriteLine( "Dog sez '{0}'" , aDog.Speak() ) ;
        Console.WriteLine( "Animal sez '{0}'" , anAnimal.Speak() ) ;

        return ;
    }
}

运行程序得到如下结果:

狗叫“汪!” 动物说“未知的声音”

获得这种行为应该要求程序员走出程序员的道路。子类实例不会因为被上转换为它的超类型而停止存在。相反,你必须显式地请求预期的(几乎总是想要的)结果:

public class Animal
{
    public virtual string Speak() { return "unknown sound" ; }
}

public class Dog : Animal
{
    public override string Speak() { return "Woof!" ; }
}

其他回答

从Ruby中的随机类继承:

class RandomSubclass < [Array, Hash, String, Fixnum, Float, TrueClass].sample
   ...
end

(首次出现在Ruby的隐藏特性中)

在PHP中,你可以这样做:

System.out.print("hello");

通知7。一个有效程序的例子:

    Chomsky is a room. 
    A thought is a kind of thing. 
    Color is a kind of value. 
    The colors are red, green and blue. 
    A thought has a color. It is usually Green. 
    A thought can be colorful or colorless. It is usually colorless. 
    An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously." 
    A manner is a kind of thing. 
    Furiously is a manner. 
    Sleeping relates one thought to one manner. 
    The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation. 
    Colorless green ideas sleep furiously. 

像图灵机模拟器这样的其他愚蠢的东西可以找到。

Ruby

时间。Parse经常假装解析没有失败,而是返回现在

require 'time'

Time.parse '2000-01-01 12:00:00'
# -> 2000-01-01 12:00:00 +0100

Time.parse '2000-99-01 00:00:00'
# -> ArgumentError: argument out of range ...

Time.parse 'now'
# -> 2010-08-13 21:26:13 +0200

Time.parse 'yesterday'
# -> 2010-08-13 21:26:18 +0200

Time.parse 'billion years ago'
# -> 2010-08-13 21:26:37 +0200

下面是一个关于python的例子:

>>> print 07
7
>>> print 08
  File "<stdin>", line 1
    print 08
           ^
SyntaxError: invalid token

那不是很美吗?

尤其当你想到人类是如何写日期的时候,你会觉得很不周到,这有以下影响:

datetime.date(2010,02,07) # ok
datetime.date(2010,02,08) # error!

(原因是0x被解释为八进制,所以打印010打印8!)