in reply to Re^2: I dislike object-oriented programming in general
in thread I dislike object-oriented programming in general
In Perl you're not really creating functions at run time (unless you're calling eval). You're creating closures. So what is really needed is to be able to create and pass around closures at run time.
C, of course, does not natively support having closures. But C does support structs, and it really isn't hard to define a struct that consists of a pointer to a function and a pointer to whatever. And then have a function to call the function pointer and pass it the other pointer. Now we have something equivalent to a closure. (Well, it doesn't do its own memory management, but let's not quibble,)
Sure, our functions that can be used that way all have to accept a random pointer to a data structure as an argument, and have to manually unpack their environment from that. It is ugly. (What do you expect from C?) But now you can use functional programming techniques in C.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: I dislike object-oriented programming in general
by Aristotle (Chancellor) on Oct 28, 2007 at 18:03 UTC | |
Re^4: I dislike object-oriented programming in general
by Anonymous Monk on Aug 14, 2011 at 16:40 UTC |