在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
下面的答案与这个关于数组的答案类似。
在Powershell中,像其他动态语言一样,字符串和数字在某种程度上是可以互换的。然而,Powershell无法下定决心。
PS> $a = "4" # string
PS> $a * 3 # Python can do this, too
444
PS> 3 * $a # Python doesn't do it this way, string repetition is commutative
12
PS> $a + 3 # Python gives a mismatched types error
43
PS> 3 + $a # Python would give an error here, too
7
如果变量是整数而不是字符串,则操作是可交换的。
PS> $a = 4 # integer
PS> $a * 3
12
PS> 3 * $a
12
PS> $a + 3
7
PS> 3 + $a
7
当有疑问时,做一个模型:
PS> $a = "4"
PS> $b = 3
PS> [int] $a * [int] $b
12
你也可以使用[float]。
其他回答
在C中,a[b][C]与C [b[a]]完全相同。
在c++中,你可以做:
std::string my_str;
std::string my_str_concat = my_str + "foo";
但你不能:
std::string my_str_concat = "foo" + my_str;
操作符重载通常服从WTF。
在SQL Server中,如果你在生产代码中使用select *,你可能会遇到一个令人讨厌的意外。无论如何,使用select *并不被认为是一个好的实践,但了解一些有趣的行为是很好的。
参见问题“select * from table”vs“select colA,colB etc from table”在SqlServer2005中有趣的行为了解更多细节
哈哈!
整个语言本身。虽然不完全是WTF的事情,但我从来没有遇到过一种语言在我的脑海中以一种刺耳的卡通声音播放。我以前也从来没有看过代码并想要惊呼“啊啊啊啊可爱!”
这个程序显示数字1-10并终止
HAI
CAN HAS STDIO?
IM IN YR LOOP UPPIN YR VAR TIL BOTHSAEM VAR AN 10
VISIBLE SUM OF VAR AN 1
IM OUTTA YR LOOP
KTHXBYE
转变;
有时你会在perl方法的第一行中看到它来读取self指针