在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
很久以前,我曾经用BUT子句构建过一种语言。
其他回答
从Ruby中的随机类继承:
class RandomSubclass < [Array, Hash, String, Fixnum, Float, TrueClass].sample
...
end
(首次出现在Ruby的隐藏特性中)
其他奇怪的事情:
在c++中,覆盖一个虚方法会隐藏该方法的所有其他重载。在Java中,这种情况不会发生。这很烦人。例如:http://codepad.org/uhvl1nJp
在c++中,如果基类有一个公共虚方法foo(),子类有一个私有方法foo(),这个私有方法会覆盖另一个方法! 这样,只需将子类对象指针强制转换为父类对象指针,就可以在类外部调用私有方法。这不应该是可能的:这违反了封装。新方法不应被视为对旧方法的重写。例如:http://codepad.org/LUGSNPdh
在PHP中,你可以定义函数来接受类型化参数(例如,对象是某个接口/类的子类),讨厌的是,在这种情况下,你不能使用NULL作为实际的参数值。 例如:http://codepad.org/FphVRZ3S
在MAXScript中,所有操作符都是平等对待的。因此,a = b +c使a等于b,然后计算a+c的和,并丢弃结果。
Perl的许多内置变量:
$# — not a comment! $0, $$, and $? — just like the shell variables by the same name $ˋ, $&, and $' — weird matching variables $" and $, — weird variables for list- and output-field-separators $! — like errno as a number but strerror(errno) as a string $_ — the stealth variable, always used and never seen $#_ — index number of the last subroutine argument... maybe @_ — the (non)names of the current function... maybe $@ — the last-raised exception %:: — the symbol table $:, $^, $~, $-, and $= — something to do with output formats $. and $% — input line number, output page number $/ and $\ — input and output record separators $| — output buffering controller $[ — change your array base from 0-based to 1-based to 42-based: WHEEE! $} — nothing at all, oddly enough! $<, $>, $(, $) — real and effective UIDs and GIDs @ISA — names of current package’s direct superclasses $^T — script start-up time in epoch seconds $^O — current operating system name $^V — what version of Perl this is
还有很多这样的东西。点击这里阅读完整列表。
有些奇怪——VBScript有一个Null关键字和一个Nothing关键字(Null是丢失的数据,Nothing是丢失的对象)。为什么不只有一个关键词…?大多数其他语言似乎都可以用一个!
Visual Basic 6.0当然还有“经典ASP”代码(因为它使用VBScript)也有同样的奇怪之处。在Visual Basic的新旧版本中,我们都有DBNull。
然而,这种情况正在改善,就像Visual Basic一样。NET Null终于消失了,所以Null不再使用,只有Nothing和DBNull被使用。