Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl Naming Conventions

by TVSET (Chaplain)
on Apr 28, 2003 at 19:50 UTC ( [id://253808]=note: print w/replies, xml ) Need Help??


in reply to Perl Naming Conventions

While there are things like perlstyle and numerous coding style guides on the web, it is still a matter of personal prefrence.

I myself got used (or still trying) to the following:

  • Objects and modules names start with capital letter (eg: My::Module).

  • Methods use underscore character ("_") as a word separator and start with the word, which describes the actrion (eg: get_value(), set_value(), print_report()).

  • Something, I've learned from PHP - start methods/subs names which return TRUE/FALSE with "is" (eg: is_valid_type(), is_valid_age(), is_logged_in()). These makes code way more readable.

  • If sub/method needs only one argument, don't use arrays, hashes, or references. Just call the damn thing! (eg:is_valid_type($type))

  • If sub/method needs more then one argument, for maintainers sake, use named arguments in hash or hash reference. (eg: print_report({-colored=>1, -monthly=>0}))

  • When it comes to parameter names, I like CGI.pm's style - with the dash. (eg {-colored=>1, -monthly=>0}).

  • I like to keep inline documentation with POD and perl comments. All irrelevant staff, like AUTHOR, NOTES, BUGS, etc (grin) I usually move to the bottom of the module file.

  • Document with POD only methods which can be called from outside. The rest should be documented with perl comments in the source. Otherwise - with POD, but should be marked explicetly.

One other thing I want to add is that coding style is not something that you think about, develop, and then use forever. It changes slowly, but constantly with the experience. Especially, if that experience is with someone else's code. :)

P.S.: In general, I don't like capitalization, since it requires me to press more keys then I need to. So I use it ONLY for significant names, which are obviously ONLY the modules. :)

P.P.S: And, yes, I beleive that set_value() is easier to read then setValue()

Leonid Mamtchenkov

Replies are listed 'Best First'.
Re: Re: Perl Naming Conventions
by leriksen (Curate) on Apr 29, 2003 at 02:22 UTC
    a thing I like to do is put a leading underscore on methods that should not be called directly e.g.
    ... sub external { ... _internal(); ... } sub _internal { }

    this is just a hint to the class user, of course. I also do the same for function-style modules, I put required methods in EXPORT, internal functions in EXPORT_OK, and provide :std and :test tags in EXPORT_TAGS that are EXPORT and EXPORT_OK e.g.
    @EXPORT = qw(external interface); @EXPORT_OK = qw(_internal _interface); %EXPORT_TAGS = (STD => \@EXPORT, TEST => \@EXPORT_OK);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found