Hacker News new | ask | show | jobs
by terryschiavo22 2611 days ago
What do first-class closures have to do with anything?
1 comments

Being able to pass a closure (lexically scoped anonymous function) as an event handler is invaluable in GUI programming.
I'm doing GUI programming for many years (from the DOS days) and while closures can be neat for small stuff (like updating an object field and calling some sort of refresh function for a visualization of the object when a GUI widget that represents the field changes), they are certainly not invaluable and you can do GUI programming perfectly fine without them - just pass a method pointer (obj+method) for C++ and similar languages (e.g. "procedure of object" or "function of object" in Object Pascal) or just a function address that takes an extra pointer (or whatever) argument that is given during handler registration (e.g. in a C toolkit of mine you register stuff with "register(widget, event, handler, param)" and handler is defined like "handler(widget, eventinfo, param)").

Actually, IMO if you are using closures for events that are more than 5 or so statements (i'd say lines but people love to pack their lines with multiple statements), you are doing a disservice for every poor soul who will have to understand your code later.

So you think C can't do that? Of course it can. Anything you want to create, C can handle it just as well if not better.
C doesn't support closures natively, so have fun building it up yourself. You can pass a function pointer. That's it.
My point is, that in C, you can do anything, including creating closures and passing them however you wish.
With enough coding, you can "do anything" in any Turing complete language. This is meaningless. It doesn't mean it is advisable (simple, maintainable) to do so. C does not support a syntax for closures, so you'll really just be calling functions with an 'environment' arg or something similar. What's the point?
My point is that he claims C can't do closures or pass them either. Follow the thread.

As far as being turing complete, CSS is supposedly that, also, so good luck with that.

You think everyone not using C is just being idiots?