Consistency is quite important.

My preference for naming just about anything is to make the names meaningful, e.g., use names like $sales_tax_rate for (duh!) sales tax rate, %population_by_city for a hash of city populations indexed by city, etc. There are no points for originality, nor are there any for cleverness.

My preference for declarations is to do so at the beginning of their scoping unit. That is, if a variable ($sales_tax_rate) is used throughout a sub, I prefer to declare it near the top of the sub, even if it's not going to be used until near the end. Loop indices (foreach $i (0 .. 100){... are declared as needed. (Note that I consider $i a perfectly sensible name for a loop index; I find the suggestion to use names like $loop_index a bit too much).

Above all, though, consistency, clarity, and simplicity. If it takes more than about 20 lines to explain a naming convention, it's probably too complex.

Naming conventions I dislike are sTuDlyCaps, runonmultiwordnameswithnovisualbreaks, and Hungarian Notation.

emc

At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

—Igor Sikorsky, reported in AOPA Pilot magazine February 2003.

In reply to Re: Naming convention for variables, subroutines, modules, etc.. and variable declaration by swampyankee
in thread Naming convention for variables, subroutines, modules, etc.. and variable declaration by Anonymous Monk

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.