special method name start with "_"
special method name start with "_"
am 28.04.2011 03:16:52 von heyi xiao
Hello all,=0AIn the source code of some bioperl modules, I saw method names=
start with "_". For instance, _print, in the following lines:=0A$self->_pr=
int($buff);=0A$self->_print("\n");
But I couldnâ=99t find the sub=
routine or function definition for these methods anywhere. Are these specia=
l or internal methods inherited from elsewhere? Any ideas? Thanks!=0AHeyi=
=0A
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 03:32:09 von Jeff Pang
2011/4/28 heyi xiao :
> Hello all,
> In the source code of some bioperl modules, I saw method names start with "_". For instance, _print, in the following lines:
> $self->_print($buff);
> $self->_print("\n");
>
These generally mean internal methods, but you could also call them
from external package.
They may be inherited from the parent class since you didn't see the definition.
Regards.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 03:36:23 von Shawn H Corey
On 11-04-27 09:16 PM, heyi xiao wrote:
> Hello all,
> In the source code of some bioperl modules, I saw method names start wi=
th "_". For instance, _print, in the following lines:
> $self->_print($buff);
> $self->_print("\n");
>
> But I couldn=92t find the subroutine or function definition for these m=
ethods anywhere. Are these special or internal methods inherited from els=
ewhere? Any ideas? Thanks!
> Heyi
>
>
I don't know mush about BioPerl but the convention for Perl objects is=20
that all methods that start with an underscore are helper methods. That =
is:
1. They are subject to change without notice.
2. They might be called directly like a sub rather than=20
$object->method( ... )
3. Documentation on them may be waaaaaaaaay out of date.
--=20
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.
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 06:20:12 von Uri Guttman
>>>>> "SHC" == Shawn H Corey writes:
SHC> On 11-04-27 09:16 PM, heyi xiao wrote:
>> In the source code of some bioperl modules, I saw method names
>> start with "_". For instance, _print, in the following lines:
>> $self->_print($buff);
>> $self->_print("\n");
>> But I couldnâ=99t find the subroutine or function definition for =
these
>> methods anywhere. Are these special or internal methods inherited
>> from elsewhere? Any ideas? Thanks!
SHC> I don't know mush about BioPerl but the convention for Perl objects =
is
SHC> that all methods that start with an underscore are helper methods.
let me correct that. methods starting with _ are conventionally private
methods. in general they should never be called from outside a
module. they can be changed and removed and the external caller
shouldn't ever know that. they don't have to have pod for them. the pod
coverage module that checks for pod for all methods will skip these
methods.
it is important to know this is a convention that many modules use but
it can be ignored or broken which is a bad idea.
uri
--=20
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com =
--
----- Perl Code Review , Architecture, Development, Training, Support ----=
--
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com -------=
--
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 06:37:45 von Shawn H Corey
On 11-04-28 12:20 AM, Uri Guttman wrote:
> methods starting with _ are conventionally private
> methods.
Actually, I think they are "protected" methods. Those methods that
should not be access by other objects but can be by their child classes.
A truly private method can be written as a sub reference:
my $private_method = sub {
# good stuff goes here
};
Since $private_method can not be access outside of the file, it is
completely private.
--
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.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 06:50:27 von Uri Guttman
>>>>> "SHC" == Shawn H Corey writes:
SHC> On 11-04-28 12:20 AM, Uri Guttman wrote:
>> methods starting with _ are conventionally private
>> methods.
SHC> Actually, I think they are "protected" methods. Those methods that
SHC> should not be access by other objects but can be by their child
SHC> classes. A truly private method can be written as a sub reference:
SHC> my $private_method = sub {
SHC> # good stuff goes here
SHC> };
SHC> Since $private_method can not be access outside of the file, it is
SHC> completely private.
and that isn't a method since it isn't in the symbol table. what you
have there is a private sub. methods must be visible to be found at
runtime. that sub isn't visible to anything except code in that block or
file.
the _ prefix is the only common way to mark a private OR protected
method as perl doesn't directly provide any support for it. moose and
other OO systems may support this.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 07:21:56 von Jeff Pang
2011/4/28 Uri Guttman :
>
> the _ prefix is the only common way to mark a private OR protected
> method as perl doesn't directly provide any support for it. moose and
> other OO systems may support this.
I may think Perl OO (not moose) doesn't have private or protected
methods as other languages like Java/Ruby.
_method can be accessed from anywhere.
package A;
sub new { bless {},shift }
sub _test { print 1 }
package B;
my $obj = A->new;
$obj->_test;
That works.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 07:29:40 von Uri Guttman
>>>>> "JP" == Jeff Pang writes:
JP> 2011/4/28 Uri Guttman :
>>
>> the _ prefix is the only common way to mark a private OR protected
>> method as perl doesn't directly provide any support for it. moose and
>> other OO systems may support this.
JP> I may think Perl OO (not moose) doesn't have private or protected
JP> methods as other languages like Java/Ruby.
JP> _method can be accessed from anywhere.
JP> package A;
JP> sub new { bless {},shift }
JP> sub _test { print 1 }
JP> package B;
JP> my $obj = A->new;
JP> $obj->_test;
JP> That works.
i said it was a convention and perl doesn't support it directly. it
means coders mark internal (a better name than protected or private)
methods with a _ prefix. as i also said the pod coverage module (used in
tests to make sure you document all your methods and subs) will skip
internal methods. this is used by most perl coders all over so it is
accepted. calling an internal method from outside the class is a bad
thing.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 07:35:04 von N
Remove me from the mailing list please
On Wednesday, April 27, 2011, Jeff Pang wrote:
> 2011/4/28 Uri Guttman :
>
>>
>> the _ prefix is the only common way to mark a private OR protected
>> method as perl doesn't directly provide any support for it. moose and
>> other OO systems may support this.
>
>
> I may think Perl OO (not moose) doesn't have private or protected
> methods as other languages like Java/Ruby.
> _method can be accessed from anywhere.
>
> package A;
>
> sub new { bless {},shift }
> sub _test { print 1 }
>
> package B;
>
> my $obj = A->new;
> $obj->_test;
>
>
> That works.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 07:36:09 von Jeff Pang
2011/4/28 N :
> Remove me from the mailing list please
>
please send an empty mail to:
beginners-unsubscribe@perl.org
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Naming subroutines WAS: special method name start with "_"
am 28.04.2011 14:53:15 von Tim Lewis
What is considered to be the proper way of naming internal subroutines?
Example:
my_special_subroutine or mySpecialSubroutine
-----Original Message-----
From: Uri Guttman [mailto:uri@StemSystems.com]
Sent: Thursday, April 28, 2011 12:50 AM
To: Shawn H Corey
Cc: beginners@perl.org
Subject: Re: special method name start with "_"
Importance: High
>>>>> "SHC" == Shawn H Corey writes:
SHC> On 11-04-28 12:20 AM, Uri Guttman wrote:
>> methods starting with _ are conventionally private
>> methods.
SHC> Actually, I think they are "protected" methods. Those methods that
SHC> should not be access by other objects but can be by their child
SHC> classes. A truly private method can be written as a sub reference:
SHC> my $private_method = sub {
SHC> # good stuff goes here
SHC> };
SHC> Since $private_method can not be access outside of the file, it is
SHC> completely private.
and that isn't a method since it isn't in the symbol table. what you
have there is a private sub. methods must be visible to be found at
runtime. that sub isn't visible to anything except code in that block or
file.
the _ prefix is the only common way to mark a private OR protected
method as perl doesn't directly provide any support for it. moose and
other OO systems may support this.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com
--
----- Perl Code Review , Architecture, Development, Training, Support
------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com
---------
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Naming subroutines WAS: special method name start with "_"
am 28.04.2011 14:56:57 von Jeff Pang
2011/4/28 Tim Lewis :
> What is considered to be the proper way of naming internal subroutines?
>
> Example:
> my_special_subroutine or mySpecialSubroutine
>
neither.
But it could be: _my_special_subroutine
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: special method name start with "_"
am 28.04.2011 16:56:05 von Peter Scott
On Thu, 28 Apr 2011 13:21:56 +0800, Jeff Pang wrote:
> I may think Perl OO (not moose) doesn't have private or protected
> methods as other languages like Java/Ruby. _method can be accessed from
> anywhere.
In your example, yes. But Moose *is* Perl's O-O, it's just a wrapper
around it. Perl provides enough flexibility to do all kinds of things.=20
See http://search.cpan.org/perldoc?MooseX::Privacy. (That's Moose-X,=20
not Moo-Sex.) Class::Std can do this too.
--=20
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=3D0137001274
http://www.oreillyschool.com/courses/perl3/
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Naming subroutines WAS: special method name start with "_"
am 28.04.2011 17:16:40 von Uri Guttman
>>>>> "TL" == Tim Lewis writes:
TL> What is considered to be the proper way of naming internal subroutines?
TL> Example:
TL> my_special_subroutine or mySpecialSubroutine
again it is a convention but perl names (other than class names) are
best done with _ as in my_special_subroutine. and if it is internal,
prefix it with _ as well.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/