in reply to Perl and Objects, how do you resolve the two?

As for good examples, I would simply look at some of the more popular modules that are referred to here often but are more than just wrappers around common functions, such as CGI.pm, DBI, Bit::Vector, and more. As for bad code... well, there's a lot of it floating around there.... :D

From all that I've read here and elsewhere on OO Perl, it's not the same as any of the other major OO languages; you can break a lot of the typical rules that 'Object Oriented' applies to, and be selective about which rules that you want to use in your code when you do OO in Perl. The fact that Perl doesn't have strong type checking also allows many more rules to be broken. The best that you can do is at least encapsulate variables, have private and public functions, and provide new instances of an object as to keep everything working. While you could easily make a 100% complete OO perl program from that, most strive to instead to encapsulate as much as they can into objects, and then use standard procedural programming with object function calls as to simplify and increase the legibility of the code.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
  • Comment on Re: Perl and Objects, how do strongyou/strong resolve the two?

Replies are listed 'Best First'.
(tye)Re: Perl and Objects, how do strongyou/strong resolve the two?
by tye (Sage) on Apr 10, 2001 at 19:48 UTC

    Please don't try to read CGI.pm as an example of how to do OO properly. *shudder*

    CGI.pm is a great module and it is currently the only option I can recommend for parsing of CGI forms. But I cringe when I think of someone reading its source code trying to figure out how to do OO. Trying to read CGI.pm's source code to figure out how, for example, the table() method works is challenge enough (for one thing, there is no table() method in the source code).

    I have a sneaking suspicion that DBI is likewise rather dense code and not something to be read in an attempt to understand OO.

    Bit::Vector is all written in C code which makes it a pretty bad example as well. Bit::Vector::Overload might be a better choice but since it makes heavy use of Bit::Vector I still can't recommend it.

    The only example OO modules that pop into my head are examples of OO mistakes. For example, Data::Dumper has an awkward interface. My Win32::TieRegistry should use a separate package for the tied hash. Array::Compare needs to provide non-OO alternatives. Exporter.pm and DynaLoader.pm shouldn't be using inheritance.

    But that makes sense since part of the point of a well-written module is that you don't trip over interface mistakes and don't run into bugs that prompt you to read the source code. (:

            - tye (but my friends call me "Tye")
      What do you think of the design of the LWP library?

        Not much. (: Urm, that is, I haven't previously thought much about the design of LWP. Since I've only used LWP a bit, I guess that is only a small indication of a reasonable design.

        Looking over my experience with it I'd have to say that I don't recall any real problems and that the design seems quite good.

        I guess my major worry about someone looking at LWP to learn OO in Perl would be that LWP is quite large, making analysis of its design more difficult.

        I also worry that LWP's success with inheritance may encourage the use of inheritance which I find is best avoided for most problem domains, at least in Perl where the only supported inheritance is implementation inheritance which is the kind that I, and others, really have a problem with.

                - tye (but my friends call me "Tye")
Re (tilly) 2: Perl and Objects, how do strongyou/strong resolve the two?
by tilly (Archbishop) on Apr 10, 2001 at 22:58 UTC
    Please do not call it strong type checking.

    Call it static type checking. Versus dynamic typing at runtime.

    Now read a few articles from which you can form your own opinions on whether static typing (at least as practiced by langauges like C++ and Java) is the greatest idea in the world...

    UPDATE
    Erm, On of those statics was supposed to be a strong and now is...