Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

WWWXXX DACB, wwwxxx,nvif, why atm producer might be held liable for economic injury, wwwxxxy=ServiceLogin, w2ksp4.exe, WwwxxXdbf, procmail "FROM_MAILER" patch, Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table

Links

XODOX
Impressum

#1: Code organization .pm

Posted on 2011-09-05 00:28:17 by Ron Weidner

--0-445087275-1315175297=:70481
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

I have a class named Widget in a file named Widget.pm.=A0 I have another cl=
ass named Table in a file called Table.pm.=A0 Table extends Widget. --=
- package Widget;=0A#file Widget.pm #insert a bunch of methods...=
  =0A--- package Table;=0A#file Table.pm=0Ause Widget;=0A@ISA=3D(=
"Widget"); #insert several methods here... 1; --- packa=
ge Framework;=0A#file Framework.pm=0Ause Widget;=0Ause Table;=0A1; ---=
What I was doing was adding "use Widget;" and "use Table;" to the top=
of the program that uses these classes.=A0 But, because I expect this libr=
ary of classes to grow significantly I created a third .pm file called Fram=
ework.=A0 Inside the Framework.pm I added the "use Widget;" and "use Table;=
" and now I only "use Framework;" in my application. #!/usr/bin/perl=
=0A#test.pl=0Ause strict;=0Ause warnings;=0Ause Framework; #This line =
of code seems replaceable by either =0A#of the next 2 commented lines=0Amy =
$some_var_of_class_widget =3D new Widget(); #uncommented, the next lin=
e of code seems to work too...=0A#my $some_var_of_class_widget =3D Widget->=
new(); #uncommented, so does the next line of code=0A#my $some_var_of_=
class_widget =3D Widget->new; my $table =3D new Table(); #insert =
several tests here... This was a guess that happened to work.=A0 My qu=
eston is if this is a common solution to reducing the number of "use" lines=
?=A0 Is there a better solution that wouldn't cause the all classes to get =
compiled at runtime every time I "use Framework;" especially since all appl=
ications that use the Framework may not need the entire suite of classes co=
ntained in the framework? --=0ARonald Weidner
--0-445087275-1315175297=:70481--

Report this message

#2: Re: Code organization .pm

Posted on 2011-09-05 08:12:03 by Shlomi Fish

Hi Ron,

On Sun, 4 Sep 2011 15:28:17 -0700 (PDT)
Ron Weidner <xecronix@yahoo.com> wrote:

> I have a class named Widget in a file named Widget.pm.  I have anoth=
er class
> named Table in a file called Table.pm.  Table extends Widget.
>=20
> ---
>=20
> package Widget;
> #file Widget.pm
>=20
> #insert a bunch of methods...  
>=20
> ---
>=20
> package Table;
> #file Table.pm
> use Widget;
> @ISA=3D("Widget");
>=20

Here you can use http://search.cpan.org/dist/parent/ or maybe
http://search.cpan.org/dist/base/ . (or just use Moose or friends).

> #insert several methods here...
>=20
> 1;
>=20
> ---
>=20
> package Framework;
> #file Framework.pm
> use Widget;
> use Table;
> 1;
>=20
> ---
>=20
> What I was doing was adding "use Widget;" and "use Table;" to the top of =
the
> program that uses these classes.  But, because I expect this library=
of
> classes to grow significantly I created a third .pm file called Framework.
> Inside the Framework.pm I added the "use Widget;" and "use Table;" and no=
w I
> only "use Framework;" in my application.
>=20

Well, in your case, "use Framework;" will be equivalent to "use Table;" (but
won't be if more classes are added.).

> #!/usr/bin/perl
> #test.pl
> use strict;
> use warnings;
> use Framework;
>=20
> #This line of code seems replaceable by either=20
> #of the next 2 commented lines
> my $some_var_of_class_widget =3D new Widget();
>=20
> #uncommented, the next line of code seems to work too...
> #my $some_var_of_class_widget =3D Widget->new();
>=20
> #uncommented, so does the next line of code
> #my $some_var_of_class_widget =3D Widget->new;
>=20
> my $table =3D new Table();
>=20

Don't use indirect object notation:

http://www.modernperlbooks.com/mt/2009/08/the-problems-with- indirect-object=
-notation.html

> #insert several tests here...
>=20

Why aren't you using Test::More and TAP?

http://search.cpan.org/perldoc?Test::Tutorial

> This was a guess that happened to work.  My queston is if this is a =
common
> solution to reducing the number of "use" lines? =20

Well, generally what I did until now was make sure that each of my classes
explicitly spelled all of its dependencies, so I knew everything would
continue to work. =20

Your solution seems fine, but may break if some of the modules export symbo=
ls
(see http://search.cpan.org/dist/Sub-Exporter/ and
http://search.cpan.org/dist/Exporter/ ), and you wish to import them as wel=
l.

> Is there a better solution
> that wouldn't cause the all classes to get compiled at runtime every time=
I
> "use Framework;" especially since all applications that use the Framework=
may
> not need the entire suite of classes contained in the framework?

Well, I've also heard of Damian Conway's http://search.cpan.org/dist/Toolki=
t/ ,
but I was told it's buggy, and it may be too magical. I should note that you
may be prematurely optimising here, so you shouldn't worry about getting a
lot of code compiled, until you are sure it's the bottleneck:

http://c2.com/cgi/wiki?PrematureOptimization

Regards,

Shlomi Fish

--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/

C++ is complex, complexifying and complexified.
(With apologies to the Oxford English Dictionary).

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message

#3: Re: Code organization .pm

Posted on 2011-09-05 14:34:33 by Shawn H Corey

On 11-09-05 02:12 AM, Shlomi Fish wrote:
> I should note that you
> may be prematurely optimising here, so you shouldn't worry about getting a
> lot of code compiled, until you are sure it's the bottleneck:
>
> http://c2.com/cgi/wiki?PrematureOptimization

I have to agree with Shlomi. I also think that you may want to consider
redesigning your architecture. Not every module is going to need to use
every other module. After all, the purpose of OOD is to encapsulate and
decouple the objects. If you think that most of your module need to use
most of the rest, then I would think that your design is not decoupled
enough. I would take a look at the architecture to see if there was a
better way to design it.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

"Make something worthwhile." -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Report this message