Re: Perl Object Creation problem...



howa escribió:
Tad McClellan 寫道:

howa <howachen@xxxxxxxxx> wrote:
lawre...@xxxxxxxxxxxxxxxxxxx ???

"howa" <howachen@xxxxxxxxx> writes:
it seems a little stupid if the class name must be the package full
name...

Perhaps this will offer enlightenement:

Suppose I have two classes Road::Apple and Fruit::Apple

#/usr/local/bin/howas-private-perl-like-language
use Road::Apple;
use Fruit::Apple;

my $thing = new Apple;

What kind of apple whould $thing be?

I don't think that was a rhetorical question, but you did not
address it.

What kind of apple whould $thing be?


One is delicious, the other not
so much.

[snip .sig, you are not supposed to quote those you know]


in other language, you also have this problem, java or c.
^^^^

What is with the "also" there?

Perl does not have that problem.


in fact, this is not a problem at all,

Then what kind of apple whould $thing be?

A red one or a brown one?

If the programmer cannot tell, then it looks like a problem to me...


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas

did you even have experience on java or c? (no offense)

how they handle namespace/package/import/include ?

of coz perl has more then one way to do it, but seems the way how perl
handle it is not a good solution.

hi, well
given a problem that could affect many languages the solution depends on the language and it might even be that the problem disappears for some language...

the import mecanism in java is there so that essentially you don't have to type long names, in perl it is not really necessary

for example, the java snippet
import org.vln.*
VeryLongName v = new VeryLongName();

in perl
you save at least the lhs part ;)
my $v = org::vln::VeryLongName->new() ; # better to stick to the arrow...

Also from the point of view of explicit documentation/maintainability I must prefer to use the full name.

anyway if you really want a short name you can use an alias
via one of the alias modules on CPAN

o use typeglob assignment (which you can read as a way of saying that 2 namespaces are equivalent)
*VLN = *Very::Long::Name;

in the context of OO I use it very little
preferring to hide this behing a module

now perl as a dynamic language has a lot more to offer

you can say
my $class = 'Very::Long::Name';
and
my $v = $class->new;

if you wish

o act on a series of classes

for my $class (@these_classes_that_do_survey_of_the worldcup)
{
my $watcher = $class->new();
$watcher->watch_football();
$watcher->save_result();
}


hth
--stephan




.



Relevant Pages

  • Re: Perl Object Creation problem...
    ... it seems a little stupid if the class name must be the package full ... Perhaps this will offer enlightenement: ... What kind of apple whould $thing be? ... Perl does not have that problem. ...
    (comp.lang.perl.misc)
  • Re: Python or PHP?
    ... > every language here and there more ways to do something. ... The best the programmer can do, as you imply, is to ... parse out into proper perl expressions. ... > lists, dictionaries, etc. etc. ...
    (comp.lang.python)
  • Re: Native language versions
    ... It is a different language which can be translated ... into perl and can use Perl modules. ... away quite a bit from the OP's notion of just translating perl keywords ... There's probably not much use for a user-accessible programming language ...
    (comp.lang.perl.misc)
  • Re: Wondering if you guys would like to comment on this
    ... >>ever tried using someone's highly customized EMACS setup? ... I've had the same experience with perl that he ... problem with any programming language, perl tends to make it worse ... I have the same rules on LISP programming that I do with perl ...
    (comp.lang.lisp)
  • Recommend an E-book Meeting the Following Criteria (Newbie, Long)
    ... I know several programming languages namely Java, Perl and C in this order ... Now I'm wondering which Python book I should get as there are so many out ... I'd like to mostly concentrate on language features but some pointers ...
    (comp.lang.python)