Hacker News new | ask | show | jobs
by abc_lisper 4878 days ago
* C: function pointer is a hack. The evidence of this is in the code. Most people don't even know it can be done, and it is rarely done in code(in some central piece no body looks at)

* Pascal: It's been a decade since I last looked at it, but I don't know if procedural type can be passed around.

* Java: Yep, Java doesn't have first class functions. Will give you that. However, in his example, Yegge was talking as if everything in Java has to be a object, and that somehow functions cannot be called without an associated object.

If you think C function pointers are a valid argument, I can provide a similar hack in java

http://pastebin.com/cSJ8ffar

You can call as many methods as you want. It is disturbing to me when people think C is some holy grail. C, at it is best, is conceptually weak. It is great for working with hardware, but for language features, it would be at the bottom of my list to look at.

1 comments

Your example is an interesting case of using anon inner classes to be able to wrap and pass back static functions.

Alas, all the alternate functions are defined in one place in advance for the caller/user of "funcMap()", which makes it hard for an app to put in definitions for a library. To get out of that, you have to make an interface than funcMap()'s container implements, and add more code -- Yegge's point! (verbosity)

It's still a useful technique, just verbose.

1. No, its not an anon inner class. Anon inner class is when you implement a interface, by defining its methods inline.

2. Yes, it is bad that we have to write all that verbose code. Java's typechecker is useless where it could be most useful, by typechecking high level types. You have to write all this code everytime to make it happy.