Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: Perl Naming Conventions

by Anonymous Monk
on Apr 28, 2003 at 19:22 UTC ( [id://253804]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Naming Conventions
in thread Perl Naming Conventions

Thanks for the link. Unfortunately the text describes only the basics.

I often OO modules on the CPAN which have the following style:

Methods:

get_value { ... }; set_value { ... };

Attributes:

my $foo = new foo( PrintError => 0, RaiseError => 1, );

One example is DBI.

Now I'm wondering if this is a convention or just because the author of the module likes it.

Replies are listed 'Best First'.
Re: Re: Re: Perl Naming Conventions
by halley (Prior) on Apr 28, 2003 at 19:51 UTC

    If more than two modules do it, it's a convention. In all matters of style, "consistency isn't."

    That said, the convention of passing named pairs is pretty commonly used. Whether the names are capitalized or punctuated varies. Whether the pairs are stored as attributes, or invoke special features, varies. It's enough of a convention that I hear that perl6 will offer a couple new features for parameter-checking these named arguments.

    I'd say the get_ and set_ naming idea is more of a porting convention to be similar to languages that can't overload their methods. The style I proposed above wouldn't work in languages or libraries which couldn't distinguish the calling context or treat the arguments differently.

    --
    [ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://253804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found