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

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


当前回答

在SQL server(至少MS)中:

这将总是求值为false:

IF @someint <> NULL

考虑到:

DECLARE @int INT

SET @int = 6

IF @int <> NULL
BEGIN
    Print '@int is not null'
END
ELSE
BEGIN
    Print '@int is evaluating to null'
END

输出将是:

@int is evaluating to null

必须这样写:

IF @someint IS NOT NULL
BEGIN
END

谁让英语专业的人加入了SQL队!:)

其他回答

在Ruby中,你可以用heredocs做一些奇怪的事情。考虑:

a = <<ONE
This is one. #{<<TWO}
This is two. #{<<THREE}
This is three.
THREE
TWO
ONE

p a # => "This is one. This is two. This is three.\n\n\n"

在ColdFusion中,文本值自动转换为各种数据类型,用于各种目的。我遇到了一个奇怪的问题,“00A”和“000”被返回为相等。事实证明,ColdFusion将“00A”解释为时间,转换为某种数字时间格式,并将其转换为0。“000”被转换为0。所以它们都被认为是相等的。那时我学习了字符串的比较函数。

PHP

$ php -r '::'
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM

WTF ? http://en.wikipedia.org/wiki/Scope_resolution_operator

为什么不说意外的T_SCOPE_RESOLUTION_OPERATOR ?

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

时间。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