在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在MATLAB(交互式数组语言,目前是TIOBE 20)中,有一个关键字end来表示数组的最后一个元素(它对应于NumPy -1)。这是一个众所周知的MATLAB语法:
myVar = myArray(end)
要从数组中间获取一个元素,通常可以这样写:
myVar = myArray( ceil( length(myArray)/2 ) )
令人惊讶的是,关键字end根本不是一个关键字,而是一种变量:
myVar = myArray( ceil( end/2 ) )
其他回答
我很惊讶没有人提到大多数类c语言中丑陋的开关case实现
switch (someInt) {
case 1:
case 2: System.out.println("Forgot a break, idiot!");
case 3: System.out.println("Now you're doing the wrong thing and maybe need hours to find the missing break muahahahaha");
break;
default: System.out.println("This should never happen -,-");
}
好在新语言正确地实现了它。
在Python中:
>>> x = 4
>>> y = 1000000
>>> x is 4
True
>>> y is 1000000
False
>>>
如果你不相信,就试试吧!
通知7。一个有效程序的例子:
Chomsky is a room. A thought is a kind of thing. Color is a kind of value. The colors are red, green and blue. A thought has a color. It is usually Green. A thought can be colorful or colorless. It is usually colorless. An idea is a thought in Chomsky with description "Colorless green ideas sleep furiously." A manner is a kind of thing. Furiously is a manner. Sleeping relates one thought to one manner. The verb to sleep (he sleeps, they sleep, he slept, it is slept, he is sleeping) implies the sleeping relation. Colorless green ideas sleep furiously.
像图灵机模拟器这样的其他愚蠢的东西可以找到。
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) );
在俄亥俄州立大学,他们用一种叫做Resolve/ c++的杂种c++语言教授编程。Resolve/ c++对一切都使用契约式设计方法。它要求您在编译后的注释中对组件和方法进行数学建模,从而强制您维护方法和对象之间的require /ensure关系。