在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
Java的访问修饰符对我来说是最近的一个WTF(因为我必须学习一点)。
显然,包比类层次结构更亲密。我不能定义对子类可见但对包中的其他类不可见的方法和属性。为什么我要将一个类的内部共享给其他类呢?
但是我可以定义对包内的每个类可见的属性和方法,但对包外的子类不可见。
不管我怎么想,我还是看不出其中的逻辑。切换访问修饰符,使受保护的行为就像它在c++中工作一样,并保持包的私有修饰符,这是有意义的。但现在不是了。
其他回答
下面是一个关于python的例子:
>>> print 07
7
>>> print 08
File "<stdin>", line 1
print 08
^
SyntaxError: invalid token
那不是很美吗?
尤其当你想到人类是如何写日期的时候,你会觉得很不周到,这有以下影响:
datetime.date(2010,02,07) # ok
datetime.date(2010,02,08) # error!
(原因是0x被解释为八进制,所以打印010打印8!)
英语中的虚拟语气。
等等,你是说编程语言吗?然后在C中使用(宏)绕过宏()的预处理器#定义。例如,如果有人使用#define free(…),(free)(…)将与free(…)不同。
Haskell's use of Maybe and Just. Maybe a is a type constructor that returns a type of Just a, but Maybe Int won't accept just an Int, it requires it to be a Just Int or Nothing. So in essence in haskell parlance Just Int is about as much of an Int as an apple is an orange. The only connection is that Just 5 returns a type of Maybe Interger, which can be constructed with the function Just and an Integer argument. This makes sense but is about as hard to explain as it can theoretically be, which is the purpose of haskell right? So is Just really JustKindaLikeButNotAtAll yea sorta, and is Maybe really a KindaLooksLikeOrIsNothing, yea sorta again.
-- Create a function that returns a Maybe Int, and return a 5, which know is definitly Int'able
> let x :: Maybe Int; x = 5;
<interactive>:1:24:
No instance for (Num (Maybe Int))
arising from the literal `5' at <interactive>:1:24
Possible fix: add an instance declaration for (Num (Maybe Int))
In the expression: 5
In the definition of `x': x = 5
> Just 5
Just 5
it :: Maybe Integer
-- Create a function x which takes an Int
> let x :: Int -> Int; x _ = 0;
x :: Int -> Int
-- Try to give it a Just Int
> x $ Just 5
<interactive>:1:4:
Couldn't match expected type `Int' against inferred type `Maybe t'
In the second argument of `($)', namely `Just 5'
In the expression: x $ Just 5
In the definition of `it': it = x $ Just 5
祝你好运读到这篇文章,我希望它是正确的。
在c++中,创建受保护抽象虚基纯虚私有析构函数的能力。
这是从受保护的抽象虚拟基继承的纯虚拟私有析构函数。
IOW,只能由类的成员或友元调用的析构函数(private),在声明它的基类(抽象基)中赋值0(纯虚),稍后将在以受保护的方式共享多重继承基(虚基)的派生类中定义/重写它。
很久以前,我曾经用BUT子句构建过一种语言。