Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Difference between Function-oriented and object-oriented in Perl

by erroneousBollock (Curate)
on Nov 23, 2007 at 05:37 UTC ( #652501=note: print w/replies, xml ) Need Help??

in reply to Difference between Function-oriented and object-oriented in Perl

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.


  • Comment on Re: Difference between Function-oriented and object-oriented in Perl

Replies are listed 'Best First'.
Re^2: Difference between Function-oriented and object-oriented in Perl
by dwm042 (Priest) on Nov 23, 2007 at 15:08 UTC
    Back in the days when objects were *just* being introduced to the world at large, the discussion usually revolved around procedural programming and object oriented programming. Given that jeshuashok is using function-oriented as opposed to procedural, it's just a matter of semantics. The potential confusion is that functional languages (e.g Lisp, Scheme, R) have yet another style..
      Yes, I tried to distinguish between 'imperative' and 'functional' programming.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2021-10-26 07:40 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (90 votes). Check out past polls.