Strangest language feature

2018-12-31 02:51发布

What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered?

Please only one feature per answer.

30条回答
初与友歌
2楼-- · 2018-12-31 03:37

APL (other than ALL of it), the ability to write any program in just one line.

e.g. Conway's Game of Life in one line in APL:

alt text http://catpad.net/michael/APLLife.gif

If that line isn't WTF, then nothing is!

And here is a video

查看更多
美炸的是我
3楼-- · 2018-12-31 03:37

In Java:

int[] numbers() {
  return null;
}

Can be written as:

int numbers() [] {
  return null;
}
查看更多
素衣白纱
4楼-- · 2018-12-31 03:37

I always wondered why the simplest program was:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Whereas it could be:

print "Hello World!"

Maybe this is to frighten computer science students in the first place ...

查看更多
春风洒进眼中
5楼-- · 2018-12-31 03:37

powerbasic (www.powerbasic.com) includes the compiler directive:

# BLOAT {bloatsize}

this increases the size of the compiled executable by <bloatsize> bytes. this was put in the compiler in case people creating the executable don't like the small size of the generated executable. it makes the EXE seem bigger to compete with bloated programming languages:)

查看更多
回忆,回不去的记忆
6楼-- · 2018-12-31 03:38

In JavaScript:

 '5' + 3 gives '53'

Whereas

 '5' - 3 gives 2
查看更多
浮光初槿花落
7楼-- · 2018-12-31 03:38

Quoting Neil Fraser (look at the end of that page),

try {
    return true;
} finally {
    return false;
}

(in Java, but behaviour is apparently the same in JavaScript and Python). The result is left as an exercise to the reader.

EDITED: As long as we are on the subject consider also this:

try {
    throw new AssertionError();
} finally {
    return false;
}
查看更多
登录 后发表回答