在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Ruby中,0在条件表达式中求值为true。
其他回答
我最喜欢的奇怪的C语言是5[“Hello World”],但因为已经发布了,我最喜欢的第二个奇怪的是Windows版本结构初始化黑客:
void someWindowsFunction() {
BITMAPINFOHEADER header = {sizeof header};
/* do stuff with header */
}
这条微妙的线条达到了以下效果:
Declares a BITMAPINFOHEADER structure Concisely sets the "size" member of the structure, without hardcoding a size constant (since many Window structures, including BITMAPINFOHEADER, follow the convention of specifying the size of the structure as the first member} Declares the version of the structure (since many Windows structures, including BITMAPINFOHEADER, identify their version by the declared size, following the convention that structures definitions are append-only) Clears all other members of the structure (a C standard behavior when a structure is incompletely initialized).
这并不奇怪或令人惊讶,但这让我总是说WTF:
语法或标识符名称的大小写敏感性。
大多数具有它的语言似乎只是因为C具有它。这样做没有什么好的理由。
对于那些不知道的人,bc是一种“任意精度计算器语言”,我经常使用它进行快速计算,特别是当涉及的数字很大的时候($是提示符):
$ bc -lq
12^345
20774466823273785598434446955827049735727869127052322369317059031795\
19704325276892191015329301807037794598378537132233994613616420526484\
93077727371807711237016056649272805971389591721704273857856298577322\
13812114239610682963085721433938547031679267799296826048444696211521\
30457090778409728703018428147734622401526422774317612081074841839507\
864189781700150115308454681772032
bc在很长一段时间内都是标准的Unix命令。
现在是“WTF功能”。这是来自man bc(强调是我的):
quit:当读取quit语句时,bc处理器被终止, 不管在哪里找到quit语句。 例如,"if (0 == 1) quit"将导致bc终止。 halt: halt语句(扩展)是一个执行的语句 导致BC处理器仅在执行时退出。 例如,"if (0 == 1) halt"不会导致bc终止,因为停止没有执行。
Delphi不关心像“word”这样的类型转换,将读取数组arr[0..65535] where pos = 65535: Arr[单词(pos + 10)]
在J中,foreign(!:)是各种函数组合在一起。左边的参数是一个类别,右边的参数通常(但不总是)是不同的增量值。的东西。例如:
2!:55 NB. Close console 9!:10 NB. Set print precision 6!:0 NB. Actual time 6!:2 NB. Execution time 4!:3 NB. Loaded scripts
当然,聪明的做法是把它们包装起来,但有些你只需要记住。顺便说一句,所有这些都是,想想看,三位一体的,有两个参数在右边,一个在左边。除非你给他们一个最终有效的论据,否则以上任何一条都不会起作用。