在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
foo是什么数据类型?
SELECT TOP 1
NULL AS foo
INTO
dbo.bar
FROM
sys.columns --trivial
为什么所有东西都归零?
SELECT CAST('' AS int), CAST('' AS datetime), CAST('' AS float)
...除了这
SELECT CAST('' AS decimal)
其他回答
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.
很简单,Erlang有很多。例如,标点符号的三种形式,
a_function(SomeVariable) ->
statements_end_with_commas(),
case PatternMatching of
0 -> now_we_end_with_semicolon;
true -> except_the_last_one
end.
%% Function definitions end with periods!
在C:
warning C4013: 'myfunc' undefined; assuming extern returning int
我记得由于某些原因没有看到警告(在一些遗留代码中有太多警告?),并且困惑于为什么从int转换会在使用非int返回函数时导致编译器错误。
编译器假设这样的东西是相当出乎意料的。
这并不奇怪或令人惊讶,但这让我总是说WTF:
语法或标识符名称的大小写敏感性。
大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。
这并不是一个真正的语言特性,而是一个实现缺陷:一些早期的Fortran编译器通过使用常量池来实现常量。所有参数都是通过引用传递的。如果你调用一个函数,例如。
f(1)
编译器会将常量池中常量1的地址传递给函数。 如果您为函数中的参数赋值,则会在程序中全局地更改该值(在本例中为1)。引起了一些挠头。