Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
But I coult not find any document which explains about the function oriented and object oriented way of using Perl modules.
I haven't really seen 'function-oriented' used as a term.

Usually it's just called 'imperative' (as opposed to 'functional' which is something else altogether).

Not everyone is going to agree with the classifications I provide below (different language backgrounds, etc), so I welcome improvements/clarifications to nomenclature.

Not all Perl modules expose both kinds of interface, and where they do it's typically (not always) because the imperative interface is there for legacy users of the module.

For imperative interfaces to modules, you get two main types:

  • "singleton": state/data held in module globals
  • "state-passing": you have to pass state/context to each call to a function.

"singleton" imperative interfaces to modules offer the least level of composability with other APIs, and must generally have access to their functions serialised to avoid confusion or corruption. In your example above, CGI is first used via a "singleton" CGI interface; all information related to the request and the response are stored in module globals inside the CGI module.

"state-passing" imperative interfaces are generally used by modules that don't have a lot of state. An example is Date::Calc; it exposes large number of functions that take simple scalars or lists and has no state data to speak of.

OO interfaces for modules seem more popular these days, mostly I guess because they're a little more composable than imperative interfaces.

Functional (lower-order FP) interfaces to modules are even less common, but can have even greater composability. File::Find and List::Util are probably good examples.

-David


In reply to Re: Difference between Function-oriented and object-oriented in Perl by erroneousBollock
in thread Difference between Function-oriented and object-oriented in Perl by jesuashok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-16 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found