Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: I dislike object-oriented programming in general

by perlfan (Vicar)
on Oct 17, 2007 at 01:30 UTC ( [id://645343]=note: print w/replies, xml ) Need Help??


in reply to Re: I dislike object-oriented programming in general
in thread I dislike object-oriented programming in general

To be accurate, only when functions are able to be manipulated at run time - i.e., are first class objects - may a language support higher order techniques. In C, you can pass in a function pointer as a parameter, but you can't create or manufacture functions on the fly.
  • Comment on Re^2: I dislike object-oriented programming in general

Replies are listed 'Best First'.
Re^3: I dislike object-oriented programming in general
by chromatic (Archbishop) on Oct 17, 2007 at 02:20 UTC
    In C, you can pass in a function pointer as a parameter, but you can't create or manufacture functions on the fly.

    You can, if you have a compiler, system, dlopen, and dlfunc!

      The first time I read a C program which wrote and executed an awk program to do the 'difficult' string manipulation changed the way that I thought about the limitations of languages.

      The need to do tricks like this were the force that drove me towards the 'just write the whole app in Perl' approach.

      The most natural way to create a high-performance program may be to write a Perl program that writes a C++ program.

      It should work perfectly the first time! - toma
Re^3: I dislike object-oriented programming in general
by tilly (Archbishop) on Oct 20, 2007 at 02:06 UTC
    Not so fast.

    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.

      The presence of the explicit struct; the necessity of manual assignment of values (as opposed to implicit capture); manual management of the memory involved: none of these can make functional-style code so ugly as the mere fact that C’s syntax provides no device for writing functions anonymously and inline.

      Once you combine the latter fact with the faults you mention, you inevitably run into a curious equivalence. Structs with function pointers; to functions written out of line; which accept a pointer to a user data struct: does that not sound oddly familiar? It should: there is no decidable distinction between writing OO-style C and functional-style C. Both involve the exact same mechanics of construction.

      Makeshifts last the longest.

      In assembler you can also do OOP, what you expect from assembler?
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://645343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found