在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。
COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.
其他回答
很简单,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++模板可以用来做一些奇怪的事情,最好的例子是“多维模拟字面量”,它使用模板来计算“绘制”形状的面积。下面的代码对于3x3矩形是有效的c++代码
#include"analogliterals.hpp"
using namespace analog_literals::symbols;
unsigned int c = ( o-----o
| !
! !
! !
o-----o ).area;
再举一个3D立方体的例子:
assert( ( o-------------o
|L \
| L \
| L \
| o-------------o
| ! !
! ! !
o | !
L | !
L | !
L| !
o-------------o ).volume == ( o-------------o
| !
! !
! !
o-------------o ).area * int(I-------------I) );
来自边远吗?
VBScript中的括号标识符
VBScript有所谓的方括号标识符,这些标识符定义在方括号中,如下所示:
[Foo]
实际上,它们非常方便,因为它们允许您以保留字命名变量和例程,调用第三方对象的方法,其名称是保留字,并且还可以在标识符中使用几乎任何Unicode字符(包括空格和特殊字符)。但这也意味着你可以和他们一起玩:
[2*2] = 5
[Здравствуй, мир!] = [Hello, world!]
[] = "Looks like my name is an empty string, isn't that cool?"
For[For[i=0]=[0]To[To[To[0]
[Next[To]([For[i=0])=[For[i=0]
Next
另一方面,括号标识符可能是一个陷阱,以防你在这样的语句中忘记引号:
If MyString = "[Something]" Then
因为If MyString = [Something] Then是一个完全合法的语法。(这就是为什么必须使用具有语法高亮显示功能的IDE !)
更多关于括号标识符的信息,请参阅Eric Lippert的博客:
VBScript琐事:括号标识符和保留字不兼容 VBScript测试答案,第六部分
再给JavaScript投一票:
parseInt('08') == 0
因为任何前导为0的数都被解释为八进制(奇怪),无效的八进制数被计算为0(坏)。我是在8月份发现这一点的,当时我几个月没碰过的代码自己崩溃了。事实证明,它本可以在10月份自行修复。
八进制支持显然已被弃用,所以未来几代的javascript将不会有这个仪式。