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

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


当前回答

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

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

其他回答

两个字:多重继承。这毫无意义,只会制造麻烦。

编辑——我指的是c++中的MI,而不是Java和其他语言中的mixins之类的。

Objective-C对字符串@的使用。示例:@"这是一个字符串。"

在Java中

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

在ruby/python/c中,你可以像这样连接字符串:

a = "foo" "bar"
print a # => "foobar"

这是我最喜欢的一个,你可以在Java中不使用main()来执行println。

这将编译和运行,给出println,但也有一个异常(java.lang。NoSuchMethodError:主要)

class Test {
    static {
        System.out.println("I'm printing in Java without main()");
    }
}