I am trying to come up with a good general practice to name methods that return data prepped for HTML::Template.
Why the focus on naming conventions for data prepped
for [mod://HTML::Template? My reason for asking that
may not be immediately obvious, so let me just make
some comments about naming conventions in general.
A lot of time, energy and brain cycles has been expended
over the last 40 or so years that the programming
profession/advocation has been around. Some naming
conventions make sense and some are downright silly.
When I worked as a resident contractor for AT&T Bell
Labs in the early to mid nineties they released a document
that spelled out a set of coding standards that not
only embodied naming conventions but how to properly
provide comments (embedded code documentation) that
looked scarily like the conventions that are used in
Java coding. For sake of illustration of my point let me
bend the rules of the Monastery a bit by offering this
sniglet of (not so great) C code:
typedef struct myStruct (
int m_i_nrecs; /* How many records? */
record *m_ptr_records /* the records */
} RecordTable;
/**
*** initRecordTable(n) -- set up the record table
***
*** Parameters:
*** n (int) how many records do we allocate?
***
*** Returns:
*** (void)
**/
void
initRecordTable(n)
int n;
{
/** blah...blah... blah... ***/
Now, the one part of the AT&T programming guideline
that I never agreed with was the prepending of member
fields with a "m_" to desginate that it is
a member of a structure. Well... duh... I know that
and so will any other programmer reading my code.
Let's take another example: this time from the Java world:
class Event {
private:
Date start_date;
Date end_date;
String description;
public:
Event() {
}
public Date getStartDate(){
return this.start_date;
}
public void setStartDate(Date d) {
this.start_date= d;
}
};
I left out the requisite comments ('cuz I'm lazy!) but I
think you get the idea.
In the Perl world I've carried over my experiences in other
languages and for the example you ask about I'd go one
of two ways.
If I wanted to have a seperate namespace for
stuff specifically HTML::Template prep into a
module.
package HTMLTPrepper;
use Exporter;
use vars qw/ @ISA @EXPORT_OK / ;
@ISA = qw/ Exporter /;
@EXPORT_OK = qw/ get_users /;
sub get_users {
# blah.. blah... blah...
return @stuff;
}
1;
Then whereever I'm using the prep subs I'll just
"use" and away I go. You've just simplified your
method names and you've isolated the namespace in one
fell swoop.
The danger to this approach is the fact that if you
reuse the name get_users elsewhere you're
apt to get confused or worse yet someone who is inheriting
this code from you may get confused as to which instance
you are referring to.
The other approach I'd think of using is along the same
lines but even more OO in nature:
package MyTemplates;
use HTML::Template;
use vars qw/ @ISA /;
@ISA = qw/ HTML::Template /;
sub get_users {
# blah blah blah...
return @stuff;
}
#
#
# and other subs.
1;
Now your new module inherts all the HTML::Template
methods and plus you can add your own localized methods
to the module and contain your namespace very nicely.
Now you use a naming convention that makes sense to you
and also if someone inherits your code they have some
sense as to what in the world you mean by
get_users and everybody's happy.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
|