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

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


当前回答

Objective-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

还有很多这样的东西。点击这里阅读完整列表。

在JavaScript中,2.0 - 1.1 = 0.8999999999999999。这是规范中实现浮点数的结果,所以它总是这样的。

在JavaScript中,undefined是一个全局变量,其默认值为原始值undefined。你可以改变undefined的值:

var a = {};
a.b === undefined; // true because property b is not set
undefined = 42;
a.b === undefined; // false

由于undefined的可变性,通过typeof检查undefined通常是一个更好的主意:

var a = {};
typeof a.b == "undefined"; // always true

学习PowerShell时发现:

试着猜一下结果数组是什么样的:

$a = 1, 2
$b = 1, 2+3
$c = 1, 2*3

答案:

1, 2
1, 2, 3
1, 2, 1, 2, 1, 2

哎哟!它动摇了我对PowerShell及其开发人员的信心。

c++中我最喜欢的一个是“公共抽象具体内联析构函数”:

class AbstractBase {
public:
    virtual ~AbstractBase() = 0 {}; // PACID!

    virtual void someFunc() = 0;
    virtual void anotherFunc() = 0;
};

我是从Scott Meyers的《Effective c++》中偷来的。看到一个方法既是纯虚拟的(通常意味着“抽象”),又是内联实现的,这看起来有点奇怪,但这是我发现的确保对象被多态破坏的最佳和最简洁的方法。