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

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


当前回答

我在试图找出一个完全没有意义但无论如何都能工作的MACRO时遇到了这个。这对于objective-c是正确的,但对于其他类型的C(或者至少是gcc编译器)也可能是正确的。

NSString *oneString = @"This " @"is " @"just " @"one " @"normal " @" string";

=

NSString *oneString = @"This is just one normal string";

C风格的字符串也是如此

char* str = "this " "also " "works";

其他回答

Perl。

输出“Foo\n”除非$ Foo;

通知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. 

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

Perl充满了奇怪但整洁的特性。

If可以用在语句之前或之后,就像这样:

print "Hello World" if $a > 1;    
if ($a > 1) { print "Hello World"; }

foreach也是如此:

print "Hello $_!\n" foreach qw(world Dolly nurse);

作为一名NHibernate爱好者,当我从Smalltalk听到be时,我非常激动……如。

a become: b

它直接将a对象更改为b,这使得编写惰性初始化代理变得很简单,因为所有对a的引用现在都将引用b。非常简洁!

我认为这是一种奇怪的语言特征,因为据我所知,没有其他语言具有这种能力。

在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队!:)