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

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


当前回答

这不是一个奇怪的功能,事实上,如果你仔细想想,它是完全有意义的,但还是给了我一个WTF时刻。

在c++(和c#)中,基类的子类不能访问基实例上的私有和受保护成员。

class Base {
protected:
 m_fooBar;
};

class Derived: public Base {
public:
 void Test(Base& baseInstance) {
  m_fooBar=1; //OK
  baseInstance.m_fooBar = 1; //Badness
  //This, however is OK:
  ((Derived&)baseInstance).m_fooBar = 1; //OK
 }
};

其他回答

“Piet是David Morgan-Mar设计的一种深奥的编程语言,他的程序是位图,看起来像抽象艺术。”

打印Piet的程序

在MOD_REWRITE

RewriteRule ^([a-zA-Z0-9_-]+)\.php$ $1/ [R,NC]
RewriteRule ^([a-zA-Z0-9_-]+)/$ $1\.php [NC,L]

将会导致:

"file.php > file > file.php > file > file.php > file >  ..."

最后:

Error 500 Too Many Redirects

(一般来说,我发现编辑.htaccess文件和构造一个正常运行的正则表达式一样乏味。)

在PHP中,必须显式地引用全局变量,并显式地使用这个->作为类变量。使重构变得有趣。如果不找到所有使用点,就不能将变量/参数提升为全局变量或类成员。

A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.

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)。