in reply to OO 2 death?

Of course!

But that's no excuse not to learn it. Without knowing what the problem domain was, i can't agree that OO was not the right choice for your job.

"Yes, I can re-use some of my modules, but most of them were special-purpose..."

What's good about OO is that it teaches you how to make those decisions: when to generalize, when to specialize.

"...script has ballooned ... Mostly due to having to make constructors ... for about 10 different objects"

Don't forget the one line constructor:

sub new { bless {}, shift }
Sorry you now have a bad taste for OO. To be honest, i would rather teach someone OO in a language like Ruby or even Java before throwing them into Perl. Perl's OO is, in my opinion, more difficult to grasp than other languages. It's easy to turn OO into a big ball of mud, it's very easy to do that with Perl OO - but, personally, i love Perl OO!

Any chance of you throwing a couple of these objects on your scratchpad? I'm really curious to see what you have done. And congrats for finishing the project!

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

Replies are listed 'Best First'.
Re: (jeffa) Re: OO 2 death?
by Cestus (Acolyte) on Dec 06, 2001 at 21:30 UTC
    :) - Actually, I did learn OO in Java b4 trying to learn it in Perl. Perl's syntax is a lot more difficult, and not as powerful - multilpe parents just aren't a good idea. I'll chuck up some objects when I get the chance, sure. I could have made it with better inheritance, but I encountered problems when using an initializer in the superclass. Had to move it down to bottom of class hierarchy. Generalizing was what I wanted to do - unfortunately my teacher saw otherwise. He also thinks that Austin Powerrs is still in (shudders *repressed memories surface*). Prob with one-line constructor is that it's 'bad form' - teacher hates not pre-declaring variables. That's what you do in Java constructors, so illogically you do that in Perl as well. I had my constructors loaded with undefs and dumb comments saying what I was doing. I'll be sure to get that on my scratchpad soon.

    Cestus

    Microsoft and Shinra are the same. They're both killing the planet.
      "Perl's syntax is a lot more difficult, and not as powerful..."

      I agree with the first statement, although understand that it gets easier with time and experience. The second statement is just plain wrong, however. The reason Perl's syntax is more difficult is because Perl IS powerful. I didn't 'get' Perl until about 2-3 years of using it.

      Remember, tye said that inheritence should mostly be considered as a last resort, and he is dead on the money. The buzz term is "favor aggregation over inheritence". Inheritance is not the best answer, as you see when you realize that a mistake was made in the parent class.

      My opinions on pre-declared variables: a maintenance nightmare. However, i do like thing such as:

      sub new { my $class = shift; my $self = { day => '', some_list => [], some_hash => {}, }; return bless $self, $class; }
      If your variables are named appropriately, you shouldn't have to add comments to explain what they are. Comments should be reserved to ideas that can't be immediately gleaned from the code, code such as this:
      # grab the pk if found, remove it and store for later use # and remove it's column from the table if (exists $self->{'pk'}) { $self->{'pk_index'} = delete $self->{'fields_hash'}->{$self->{'pk'} +}; splice(@{$self->{'fields_arry'}},$self->{'pk_index'},1) if defined $self->{'pk_index'}; }

      And yes, that one-liner constructer is bad form. If you thought that was bad, then how about this:

      sub get_attrib { shift->{shift} }
      ;)

      jeffa

      Austin Powers / 0