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

In reply to Re: Consistent naming for methods that return HTML::Template prepped data? by blue_cowdawg
in thread Consistent naming for methods that return HTML::Template prepped data? by leocharre

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.