在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
PHP
来自在线文档: string implode (string $glue, array $pieces) -用字符串连接数组元素 注意:由于历史原因,implode()可以以任意一种顺序接受其形参。
这是可行的:implode($someArray, $glue)
希望他们能在PHP 6中消除这些历史怪癖。
其他回答
这个古老的PHP宠儿本身并不完全是WTFish,但作用域解析错误是许多开发人员看到的事情之一,值得给一些WTF的爱:
$class = new StdClass();
$class::test();
PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 3
c++(或Java)中没有封装的事实。任何对象都可以违反任何其他对象的封装,破坏它的私有数据,只要它是相同的类型。例如:
#include <iostream>
using namespace std;
class X
{
public:
// Construct by passing internal value
X (int i) : i (i) {}
// This breaks encapsulation
void violate (X & other)
{
other.i += i;
}
int get () { return i; }
private:
int i;
};
int main (int ac, char * av[])
{
X a(1), b(2), c(3);
a.violate (c);
b.violate (c);
cout << c.get() << endl; // "6"
}
Powerbasic (www.powerbasic.com)包含编译器指令:
# BLOAT {bloatsize}
这将使编译后的可执行文件的大小增加<bloatsize>字节。这是放在编译器中,以防创建可执行文件的人不喜欢生成的可执行文件的小尺寸。它使EXE看起来更大,以与臃肿的编程语言竞争:)
在Java中,如果x的值为NaN,则x == x返回false, x != x返回true。
Python的三元操作符
在Python中,C三元操作符(c++示例:bool isNegative = i < 0 ?True: false;)可用作语法糖:
>>> i = 1
>>> "It is positive" if i >= 0 else "It is negative!"
'It is positive'
>>> i = -1
>>> "It is positive" if i >= 0 else "It is negative!"
'It is negative!'
这并不奇怪,而是一种特征。奇怪的是,与C中的顺序(条件?答:b)。