在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

c#中的“动态”。

因为智能感知、类型安全和决定论会随着“动态”关键字的第一次使用而立即消失,因此所有必须与RAD或python受害者一起工作的人的日子都被毁了。

其他回答

在Bash中,变量可以显示为标量和数组:

$ a=3
$ echo $a
3
$ echo ${a[@]}    # treat it like an array
3
$ declare -p a    # but it's not
declare -- a="3"
$ a[1]=4          # treat it like an array
$ echo $a         # acts like it's scalar
3
$ echo ${a[@]}    # but it's not
3 4
$ declare -p a
declare -a a='([0]="3" [1]="4")'
$ a=5             # treat it like a scalar
$ echo $a         # acts like it's scalar
5
$ echo ${a[@]}    # but it's not
5 4
$ declare -p a
declare -a a='([0]="5" [1]="4")'

KSH做同样的事情,但是使用排版而不是声明。

当你在zsh中这样做时,你得到的是子字符串赋值而不是数组:

$ a=3
$ a[2]=4          # zsh is one-indexed by default
$ echo $a
34
$ a[3]=567
$ echo $a
34567
$ a[3]=9
$ echo $a
34967
$ a[3]=123         # here it overwrites the first character, but inserts the others
$ echo $a
3412367
$ a=(1 2 3)
$ echo $a
1 2 3              # it's an array without needing to use ${a[@]} (but it will work)
$ a[2]=99          # what about assignments?
$ echo $a
1 99 3

在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

在PHP中:

<?php
$o = new stdClass;
echo count($o);
?>

..打印1。一直不知道为什么。

在Coldfusion中,任何地方的变量都被视为全局变量,无论它们放在哪里。

<cffunction name="one" returntype="void">
    <cfset var wtf="coldfusion">
    <cfinvoke method="second">
</cffunction>

<cffunction name="two" returntype="void">
    <cfoutput>#wtf#</cfoutput>
</cffunction>

很久以前,我曾经用BUT子句构建过一种语言。