[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] do... while? SPOILER



I'm not sure I see why you need the objects at all.  That is, couldn't you
do your example as a normal hash.  The "added" maintenance would be that the
"constructor" (where you initialize the hash) would need the names of the
values, in addition to the actual values.  But the savings in maintenance
would be, as you point out, the lack of all these classes floating around.
So, if as you say, the class is just a bunch of accessor methods, just do:

my %Object1 = (a1 => $a1, a2 => $a2);

Then the accessor "Object1->geta1" becomes "$Object1{a1}", etc.

 - Andy Jacobs

-----Original Message-----
From: owner-fwp@technofile.org [mailto:owner-fwp@technofile.org]On
Behalf Of Tushar Samant
Sent: Saturday, July 03, 1999 2:26 PM
To: Fun With Perl
Subject: Re: [FWP] do... while? SPOILER


> Was it fun? (I have fun rewriting this sort of stuff...)

Here is a sample of something I want to rewrite (this is not the
actual code, just the pattern):

  package Object1;

  sub new {
    my $class = shift;
    my($a1, $a2) = @_;
    my %self = (
      'a1', $a1,
      'a2', $a2,
    );
    bless \%self, $class;
    return \%self;
  }

  sub geta1 {
    return $_[0]->{a1};
  }

  sub geta2 {
    return $_[0]->{a2};
  }

And on and on, world without end, over 20 packages with a hundred
attributes.
No aggregates, no inheritance--nothing, absolutely nothing except hashes and
get functions. (And incomprehensible error reporting, direct prints to
stdout,
C<die>s, finicky bounds-checking of unfathomable intent... but I digress.)

OK, it's funny. The trouble is, these are the sorts of programs which are
used to "prove" that Perl is unwieldy and hard to maintain... because e.g.
adding one attribute to one class turns into "maintenance". And the most
humorous thing of all is: what was all this farcical abstraction for? Yes,
"to separate implementation from interface". Sure. Now imagine trying to
change the implementation...

I say--not only will *programmers* of Perl quickly get the same effect as
the 20 solemn "classes" above, but they will actually enjoy it. Question:
how would you do it?

PS: As I said, I -want- to rewrite this. But be assured that there will
be people who will call it a waste of time, or cryptic, or hackish, and
say don't fix what ain't broken, and generally act like they are Fred
Brooks himself...

PPS: Thanks for all the suggestions about "persuading" my coworker. They
will be tried out soon...

--
Tushar Samant
~
~
:wq


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe