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

Re: module w/ object-oriented and functional interfaces: best practices?

by BrowserUk (Patriarch)
on Sep 21, 2012 at 17:41 UTC ( [id://994957]=note: print w/replies, xml ) Need Help??


in reply to module w/ object-oriented and functional interfaces: best practices?

Kinda hard to advise seeing as you don't want to re-write your procedural (functional has other connotations), stuff, but haven't shown us what it looks like.

At the simplest level, a method is just a function that has a hashref (or other ref) pointing to the data it is to operate on, as its first argument.

If your procedural functions were written (or could be easily modified) to take a hashref containing the data they operate on, then making the module "OO" could be as simple as adding a constructor sub that builds a hash from its inputs, blesses a reference to it and returns it.

That way, all your existing subs become methods also, if the reference to the data is blessed,o with no further work required.

It probably wouldn't be "good OO"; but it would satisfy the requirement of having both styles of interface.

But then the question becomes; why do you want two styles of interface?

Individual problems/libraries generally lend themselves best to one or the other. Having both is often no more than paying lip service to peoples wont to have things work in one particular way.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

  • Comment on Re: module w/ object-oriented and functional interfaces: best practices?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found