Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I disagree on whether merlyn's comments on this topic are Cargo-Cult programming. To say that it is is to say that this is a topic that he, has not thought about and does not understand.

To the contrary, merlyn has done OO programming for 20 years, and has done OO programming in Perl for as long as Perl has had support for it. In that time he has seen many different approaches to OO programming, in quite a few languages, and has developed strong opinions on the subject. I would be very, very wary about claiming that he has not thought about the relevant issues, or claiming that he doesn't understand OO programming in Perl.

Now Perl's OO is, you claim, a simple idea. Not so fast. Perl's OO is a simple implementation of a fundamental concept. The fundamental concept behind OO programming is that it provides support for modelling your programming universe, and then later using that model to find good solutions for your problems. The implementation in Perl is simple partly because other features in Perl make it easy to do whatever you want. The amount of OO specific flexibility that needs to be added is little, but the OO model you get is more complex. And the potential OO models are even more complex.

So back to what OO is. I claimed that OO is about ways of creating conceptual models and then working with that. The key idea is indeed to create "things" that you can interact with. The things contain internal data, and are bound to methods. The modelling tools that you use to create your models of the things vary, but modelling is the job.

Now if you are going to be modelling, then it is important to think about what kinds of models you want and why. And part of that is your model of what the relationship is between a class and an object in that class. merlyn's point, and mine, is that when you use the ref || $proto trick, what you are really doing is making it possible to confuse the object and the class. As I, and merlyn, point out, this confusion will only work partway. While sometimes the effect can be useful, most of the time the model is misleading.

Which is why I say that most of the time you should either not do that, or else you should go the rest of the way. I am not saying that you should program Perl like it was Smalltalk. I am saying that to whatever extent possible you should encourage clear mental models of your classes. Don't reflexively type in an idiom because you have seen it. Stop, think about whether it is what you want, and then conciously choose whether you want it.

Now to address a fundamental issue. While it is true that when merlyn is hired to do a code review, he flags that item, my experience is that this is a provisional opinion. If you point out why you did it, and have a reason, he has no trouble going, "OK, you know what you are doing" and takes back what he said. It is like strict. Most of the time it is a danger flag. But sometimes, based on what the code is doing, strict really can't be used. The rule that is true 95% of the time isn't always true.

For instance take a look at Re (tilly) 1: Nested Classes for an example where I used the ref||$proto idiom. As I commented in the code, it wasn't Cargo-cult. And merlyn sent me a private note about that when he says that he only minds seeing that construct in the code of people who don't really understand what is going on. But he says that in that code he would not have flagged it.

And a final few corrections. First of all I think that other languages can do a lot more with OO than you give them credit for. Secondly mathematicians do not do anything particular with OO, in fact most do not even know what the heck it is. And finally given my background, I am far more likely to see other languages through Perl tinged glasses than vice versa...

In reply to Re (tilly) 4: Paradigm Shift - Dual Use Constructors by tilly
in thread Paradigm Shift - Don't use strict by Ovid

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2021-10-16 03:02 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (69 votes). Check out past polls.