在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
APL(除了ALL),在一行中编写任何程序的能力。
例:在APL中,康威的生命游戏一行:
替代文本 http://catpad.net/michael/APLLife.gif
如果这句台词都不是WTF,那什么都不是!
这是一个视频
其他回答
另一个C-ism。
int i= 0;
while( i != 12 ) {
/* Some comment
i += 1;
/* Another comment */
}
为什么不行?棉绒会告诉你。然而,C编译器通常会轻松地忽略这一点。我也是。
当我发现问题出在哪里的时候,那真是太棒了。
在Java中从文本文件中读取一行。
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("filename"));
String str;
str = in.readLine();
if (str != null) {
...
}
} catch (IOException e) {
...
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {}
}
啊。虽然我承认这并不奇怪……只是邪恶。: -)
更短、更习惯的版本:
try {
BufferedReader in = new BufferedReader(new FileReader("filename"));
try {
String str = in.readLine();
while (str != null) {
str = in.readLine();
}
} finally {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
c#的默认继承模型赢得了我的投票:
public class Animal
{
public string Speak() { return "unknown sound" ; }
}
public class Dog : Animal
{
public string Speak() { return "Woof!" ; }
}
class Program
{
static void Main( string[] args )
{
Dog aDog = new Dog() ;
Animal anAnimal = (Animal) aDog ;
Console.WriteLine( "Dog sez '{0}'" , aDog.Speak() ) ;
Console.WriteLine( "Animal sez '{0}'" , anAnimal.Speak() ) ;
return ;
}
}
运行程序得到如下结果:
狗叫“汪!” 动物说“未知的声音”
获得这种行为应该要求程序员走出程序员的道路。子类实例不会因为被上转换为它的超类型而停止存在。相反,你必须显式地请求预期的(几乎总是想要的)结果:
public class Animal
{
public virtual string Speak() { return "unknown sound" ; }
}
public class Dog : Animal
{
public override string Speak() { return "Woof!" ; }
}
在Java中(这是一个导致赋值的if语句)
result = (Boolean condition) ? (if Boolean is true) : (if Boolean is false);
or
data Nat = Z|S Nat deriving Show
nattoInt Z = 0
nattoInt (S a) = 1 + nattoInt a
buildNat 0 = Z
buildNat a = S (buildNat (a - 1))
在Haskell…我仍然不太明白这是如何定义自然数的(我完全理解理论:-p)
在早期版本的Visual Basic中,没有“Return”语句的函数只是“Return None”,没有任何编译器警告(或错误)。
这导致了最疯狂的调试会话,那时我必须每天处理这种语言。