in reply to Naming convention for variables, subroutines, modules, etc.. and variable declaration

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.
  • Comment on Re: Naming convention for variables, subroutines, modules, etc.. and variable declaration