在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
通知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.
像图灵机模拟器这样的其他愚蠢的东西可以找到。
其他回答
这并不是说它被大量使用,而是c++的“返回对静态大小数组的引用”的语法很奇怪:
struct SuperFoo {
int (&getFoo() const)[10] {
static int foo[10];
return foo;
}
}
在上述情况下,Ofc方法可以声明为静态const
PHP (?)
第一:(未设置)类型转换。
$a = 1;
$b = (unset)$a;
var_dump($a); // 1
var_dump($b); // NULL
用法:http://www.php.net/manual/en/language.types.type-juggling.php # 89637
第二:= NULL和unset()函数之间的区别。
$c = 10;
$d = &$c;
$c = NULL;
var_dump($c); // NULL
var_dump($d); // NULL
$e = 10;
$f = &$e;
unset($e);
var_dump($e); // NULL
var_dump($f); // 10 - WTF?
在Python中,函数参数的“编译时”(或声明时)计算可能令人困惑:
def append(v, l = []):
l.append(v)
return l
print append(1)
print append(2)
>>> [1]
>>> [1,2]
其意图可能是:
def append(v, l = None):
if l is None:
l = []
l.append(v)
return l
print append(1)
print append(2)
>>> [1]
>>> [2]
这种行为对于缓存之类的事情很有用,但它可能是危险的。
附加特性:具有可变内容的元组:
a = (1,2,[3])
a[2][:] = [4] # OK
a[2] = [2] # crashes
C的多个名称空间:
typedef int i;
void foo()
{
struct i {i i;} i;
i: i.i = 3;
printf( "%i\n", i.i);
}
或与字符:
typedef char c;
void foo()
{
struct c {c c;} c;
c: c.c = 'c';
printf( "%c\n", c.c);
}
很简单,Erlang有很多。例如,标点符号的三种形式,
a_function(SomeVariable) ->
statements_end_with_commas(),
case PatternMatching of
0 -> now_we_end_with_semicolon;
true -> except_the_last_one
end.
%% Function definitions end with periods!