在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在ColdFusion中,文本值自动转换为各种数据类型,用于各种目的。我遇到了一个奇怪的问题,“00A”和“000”被返回为相等。事实证明,ColdFusion将“00A”解释为时间,转换为某种数字时间格式,并将其转换为0。“000”被转换为0。所以它们都被认为是相等的。那时我学习了字符串的比较函数。
其他回答
JavaScript是面向对象的,对吧?因此,在文字字符串和数字上运行方法应该是可行的。比如"hello". touppercase()和3.toString()。第二个是语法错误,为什么?因为解析器期望一个数字后面跟一个点是一个浮点字面值。这不是WTF, WTF是你只需要再加一个点就可以了:
3..toString()
原因是字面上的3。被解释为3.0,3.0. tostring()工作正常。
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# has a feature called "extension methods", which are roughly analogous to Ruby mix-ins - Essentially, you can add a method to any pre-existing class definition (for instance, you oould add "reverse()" to String if you were so inclined). That alone is fine- The "Weird" part is that you can add these extension methods, with a method body and everything, to an interface. On the one hand, this can be handy as a way to add a single method to a whole swath of classes which aren't part of the same inheritance tree. On the other, you're adding fleshed out methods to interfaces, essentially breaking the very definition of an interface.
MySQL枚举,特别是他们的能力,使生活的地狱毫无准备的同事。
CREATE TABLE foo (
....
dispatched ENUM('0','1') NOT NULL DEFAULT '0',
)
然后:
UPDATE TABLE foo SET ..., dispatched = 1;
哎呀,dispatch被设置为0,因为1没有被引用。这真的惹恼了为我编写代码的人;我现在使用普通的int。
在一个相关的注意事项,即使你添加一个空字符串选项到你的枚举,例如。
blah ENUM('','A','B') NOT NULL,
如果给blah赋了一个无效值,MySQL将使用一个秘密隐藏的空字符串值来表示无效值,这将很难与您自己添加的值区分开来。耶!
在Java中,
Int x = 010;
这将x赋值为8。
在Java中,任何前面带0的整数都被假定为八进制。