in reply to Procedural and Object Oriented Perl Code

Procedural code uses stuff like loops and subroutines to manipulate data that is stored in either global data structures or is passed around as parameters.

Object oriented code ties the data up into a bundle called an "object" and associates "methods" with the object. The idea is that you can create objects where the details of how the data can be manipulated is embodied in the object rather than being a bunch separate subroutines and data that get munged together in some fairly haphazard fashion.

The big gain with object oriented programming comes when define the objects in terms of classes and allow the same data manipulation to be applied to different but related data.

An example might be a class that wraps up some database functionality for dealing with tables. So you might have a Table class that allows you to provide the name and structure of the table (the data) and allows you to do things like create the table (given a database handle - most often an object actually) and then do stuff with it like insert new records into the table, fetch records, update records and soon. The nice part is that once you have written the method to do each trick it really doesn't matter what the details of the table are, the methods work for all tables.


DWIM is Perl's answer to Gödel
  • Comment on Re: Procedural and Object Oriented Perl Code

Replies are listed 'Best First'.
Re^2: Procedural and Object Oriented Perl Code
by BrowserUk (Patriarch) on Mar 31, 2007 at 13:17 UTC

    Update: corrected typo noted below. Thanks RobPayne

    Loops occur in both those programming styles, as well as functional programming where they may be disguised as recursion, and monolithic coding and assembler programming as gotos. They do not form a distinguishing point at all.


    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.
      I agree with the point BrowserUk is attempting to make, but the last sentence should be "They do *not* form a distinguishing point at all." It was a small typo, but it makes all of the difference.