在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
Delphi不关心像“word”这样的类型转换,将读取数组arr[0..65535] where pos = 65535: Arr[单词(pos + 10)]
其他回答
在c++中,“虚”MI(多重继承)允许“菱形”类层次结构“工作”,这让我觉得奇怪和讨厌。
A:基类,例如:“对象” B, C:两者都(实际上或不是)源于对象和 D:起源于B和C
问题:“正常”继承导致D是2种不明确的A。“虚拟”MI将B的A和C的A折叠为一个共享基对象A。
所以,即使你的车轮是一个对象,你的左前轮是一个车轮,你的汽车继承了四种车轮,你的汽车仍然只是一种具有虚拟MI的对象。否则,你的汽车不是一个对象,而是4个车轮对象。
这是一种奖励糟糕的类设计、惩罚编译器编写者的语言特性,并让您在运行时怀疑对象到底在哪里——以及是否有任何虚拟MI行李放错了地方。
如果在类层次结构中确实需要菱形模式,可以使用常规MI和委托给单个A基的“AProxy”来完成。
A:基类,例如:“对象” AProxy:基类,与其他A绑定的构造 B:源自A C:来源于AProxy D:源自B和C(在构造时将B的A传递给C的AProxy)
对于那些真正喜欢diamond MI的人来说,这需要做更多的工作,而我们其他人则可以安心地使用一组更易于处理的语言特性。
这缺少了一个奇怪的特性:Python没有switch语句(尽管存在变通方法)。
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.
在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
我有点纠结:
1;
在perl中,模块需要返回true。