在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.
其他回答
当我在大学的时候,我用一种叫做SNOBOL的语言做了一点工作。整个语言虽然很酷,但却是一个大WTF。
它的语法是我见过的最奇怪的。而不是GoTo,你使用:(标签)。当你有:S(label)(成功/true时的goto标签)和:F(label)(失败/false时的goto标签)并且你在一行中使用这些函数检查某些条件或读取文件时,谁还需要if呢?所以这个表述是:
H = INPUT :F(end)
将从文件或控制台读取下一行,如果读取失败(因为到达EOF或任何其他原因),将转到标签“end”。
然后是$ sign操作符。它将使用变量中的值作为变量名。所以:
ANIMAL = 'DOG'
DOG = 'BARK'
output = $ANIMAL
将在控制台上显示'BARK'值。因为这还不够奇怪:
$DOG = 'SOUND'
将创建一个名为BARK的变量(参见上面分配给DOG的值),并赋予它一个“SOUND”的值。
你看得越多,情况就越糟。我所发现的关于SNOBOL的最好的陈述(来自链接文本)是“该语言的强大功能及其相当惯用的控制流特性使得编写后的SNOBOL4代码几乎不可能阅读和理解。”
在Java中,字符串如何处理==操作符取决于它是如何构造的,这存在一些不一致性。
String a = "Hello";
String b = "Hello";
System.out.println(a == b ); // prints true.
String c = new String("Hello");
String d = new String("Hello");
System.out.println(c == d ); // prints false
C和c++中的三联体。
int main() {
printf("LOL??!");
}
这将打印LOL|,因为trigraph ??!转换为|。
很简单,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!
好吧,既然问题是断断续续的,我就加入到“有趣”中来
Go(又名Issue9)使用大写的可见性:
如果你用大写字母命名某个东西,它就会被公众访问。 如果你使用小写,它将被包保护:
包装外可见:
func Print(v ...) {
}
包外不可见
func print( v ... ) {
}
你可以在这个原始答案中找到更多。