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

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


当前回答

我想说的是,Python的空白是我最棒的WTF特性。的确,你或多或少会在一段时间后习惯它,而且现代编辑器使它更容易处理,但即使在过去一年里我几乎全职从事python开发,我仍然相信这是一个坏主意。我已经阅读了所有背后的原因,但说实话,它妨碍了我的工作效率。差不了太多,但鞍下还是有毛刺。

编辑:从评论来看,有些人似乎认为我不喜欢缩进我的代码。这是一个不正确的评估。无论使用什么语言,无论是否被迫,我总是将代码缩进。我不喜欢的是,缩进定义了一行代码所在的块。我更喜欢使用显式分隔符。除其他原因外,我发现显式分隔符更容易剪切和粘贴代码。

例如,如果我有一个缩进4个空格的块,并将它粘贴到一个缩进8个空格的块的末尾,我的编辑器(所有编辑器?)不知道粘贴的代码是属于8个空格的块还是外部块。OTOH,如果我有显式分隔符,很明显,代码属于哪个块以及它应该如何(重新)缩进——它通过智能地寻找块分隔符来做到这一点。

编辑2:一些提供评论的人似乎认为这是一个我讨厌的功能,或者我认为这使得python成为一种糟糕的语言。同样,这不是真的。虽然我不太喜欢它,但这不是重点。这个问题是关于最奇怪的语言特征,我认为这很奇怪,因为它是非常非常少(但是>0)语言使用的东西。

其他回答

SQLite允许你用你想要的任何数据类型来声明列。它查找一些特定的子字符串(“INT”、“REAL”、“TEXT”等)来确定相关性。

这使得它可以在你的类型声明:

CREATE TABLE Quirks (
   X    FLOATING POINT,  -- = INTEGER affinity because of the "INT"
   Y    STRING,          -- = NUMERIC affinity
);

通知7。一个有效程序的例子:

    Chomsky is a room. 
    A thought is a kind of thing. 
    Color is a kind of value. 
    The colors are red, green and blue. 
    A thought has a color. It is usually Green. 
    A thought can be colorful or colorless. It is usually colorless. 
    An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously." 
    A manner is a kind of thing. 
    Furiously is a manner. 
    Sleeping relates one thought to one manner. 
    The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation. 
    Colorless green ideas sleep furiously. 

像图灵机模拟器这样的其他愚蠢的东西可以找到。

在PHP中,“true”,“false”和“null”是常量,通常不能被重写。但是,随着PHP >=5.3中名称空间的引入,现在可以在除全局名称空间之外的任何名称空间中重新定义这些常量。这可能导致以下行为:

namespace {
    define('test\true', 42);
    define('test\false', 42);
    define('test\null', 42);
}

namespace test {
    var_dump(true === false && false === null); // is (bool) true
}

当然,如果希望真值为真,总是可以从全局名称空间导入真值

namespace test {
    var_dump(\true === \false); // is (bool) false
}

在Java中,

Int x = 010;

这将x赋值为8。

在Java中,任何前面带0的整数都被假定为八进制。

INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。

COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.