在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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队!:)

其他回答

PHP作为一门完整的语言基本上是WTF。

语言定义(参见www.php.org)不是由语法或标准定义的,而是由一堆“你可以写这个例子”的部分(当然,你可以写其他东西,只是猜测泛化)定义的,诚实的用户说“但它做了这种古怪的事情……”。

在使用我们构建的PHP解析器时,我经常会遇到一些故障。这是最新的消息:

 "abc$A[define]def"

现在,PHP是PERL的一个(非常糟糕的)副本,因此它允许用隐式变量替换构造字符串。字符串中的$X表示“将$X的值插入字符串”,相当于“abc”。$ X。"def",其中"."是PHP的字符串连接操作符。

字符串中的$A[7]表示“将数组$A的第七个槽的值插入字符串”,相当于“abc”。美元[7]。“def”。

现在,语言(网站)清楚地说“定义”是一个关键字,你不能 只要你能找到合适的表达就用它。那么上面包含“define”的宝石做什么呢?抛出语法错误?不,那样说得通。

不,它实际上的意思是:

 "abc" . $A["define"] . "def"

只有当你在一个字符串的简单数组访问中写一个看起来像标识符(关键字或不是!)的东西时,它才会这样做。在语言的其他地方没有这种行为。 什么,写“abc$A["define"]def”是不合理的,所以PHP发明者不得不把它扔进去?得了吧。(更严重的是,“字符串中有复杂的数组访问”,当然它的工作方式不同。查看"abc{$A[define]}def";根据PHP网站,这是非法的。

(PHP数组是关联哈希表,因此根据名称查找数组(嗯,哈希表)成员并不是一个糟糕的想法)。

语言中充满了这样的陷阱。如果你喜欢“天哪,看看我今天在子程序下发现了什么蠕动的东西”,你应该切换到PHP。

大约在1977年,我在Lisp中添加了“format”函数,那时“printf”甚至还不存在(我是从与Unix相同的源:Multics复制的)。它一开始很无辜,但后来被一个接一个的特征填满了。当Guy Steele引入迭代和相关特性时,事情就失控了,这些特性被Common Lisp X3J13 ANSI标准所接受。下面的示例可以在Common Lisp The Language, 2nd Edition第22.3.3节中的表22-8中找到:

(defun print-xapping (xapping stream depth)
  (declare (ignore depth))
  (format stream
      "~:[{~;[~]~:{~S~:[->~S~;~*~]~:^ ~}~:[~; ~]~ ~{~S->~^ ~}~:[~; ~]~[~*~;->~S~;->~*~]~:[}~;]~]"
      (xectorp xapping)
      (do ((vp (xectorp xapping))
           (sp (finite-part-is-xetp xapping))
           (d (xapping-domain xapping) (cdr d))
           (r (xapping-range xapping) (cdr r))
           (z '() (cons (list (if vp (car r) (car d)) (or vp sp) (car r)) z)))
          ((null d) (reverse z)))
      (and (xapping-domain xapping)
           (or (xapping-exceptions xapping)
           (xapping-infinite xapping)))
      (xapping-exceptions xapping)
      (and (xapping-exceptions xapping)
           (xapping-infinite xapping))
      (ecase (xapping-infinite xapping)
        ((nil) 0)
        (:constant 1)
        (:universal 2))
      (xapping-default xapping)
      (xectorp xapping)))

我发现Javascript Date Object对110年的热爱令人愉快。 试一试。

<Script language ="JavaScript">
<!--
var now = new Date()
var dia = now.getDay()
var mes = now.getMonth()
var fecha

//Day of the week
if(dia==0){
 fecha="Domingo, ";
}else if(dia==1){
 fecha="Lunes, ";
}else if(dia==2){
 fecha="Martes, ";
}else if(dia==3){
 fecha="Miércoles, ";
}else if(dia==4){
 fecha="Jueves, ";
}else if(dia==5){
 fecha="Viernes, ";
}else{
 fecha="Sábado, ";
}

fecha = fecha + now.getDate() + " de "
//Which month is it?
if(mes==0){
 fecha=fecha + "Enero"
}else if(mes==1){
 fecha=fecha + "Febrero"
}else if(mes==2){
 fecha=fecha + "Marzo"
}else if(mes==3){
 fecha=fecha + "Abril"
}else if(mes==4){
 fecha=fecha + "Mayo"
}else if(mes==5){
 fecha=fecha + "Junio"
}else if(mes==6){
 fecha=fecha + "Julio"
}else if(mes==7){
 fecha=fecha + "Agosto"
}else if(mes==8){
 fecha=fecha + "Septiembre"
}else if(mes==9){
 fecha=fecha + "Octubre"
}else if(mes==10){
 fecha=fecha + "Noviembre"
}else{
 fecha=fecha + "Diciembre"
}

//Year
fecha = fecha + " del " + now.getYear()

document.write(fecha);
//-->
</Script>

脚本是西班牙语-抱歉如果你不明白代码..这个想法是为了让你看到110年的结果。

在Java中

String("aaa")==String("aaa") //false
//you need to use
String("aaa").equals(String("aaa")) // true

在一个奇怪的银行系统中使用RSL编程语言。数组有内置类TArray。但如果你从它继承,每个实例变量都成为数组的一个元素。

class (TArray) DerivedArray
  var someField = 56;
end

var a = DerivedArray();
PrintLn(a.Size);     // => 1
PrintLn(a[0]);       // => 56