in reply to (jeffa) Re: OO 2 death?
in thread OO 2 death?

:) - 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.

Replies are listed 'Best First'.
(jeffa) 3Re: OO 2 death?
by jeffa (Bishop) on Dec 06, 2001 at 23:10 UTC
    "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