Section 3.5. Underscores


3.5. Underscores

Use underscores to separate words in multiword identifiers.

In English, when a name consists of two or more words, those words are typically separated by spaces or hyphensfor example, "input stream", "key pressed", "end-of-file", "double-click".

Since neither spaces nor hyphens are valid characters in Perl identifiers, use the next closest available alternative: the underscore. Underscores correspond better to the default natural-language word separator (a space) because they impose a visual gap between the words in an identifier. For example:

      FORM:     for my $tax_form (@tax_form_sequence) {         my $notional_tax_paid             = $tax_form->{reported_income} * $tax_form->{effective_tax_rate};         next FORM if $notional_tax_paid  < $MIN_ASSESSABLE;         $total_paid             += $notional_tax_paid - $tax_form->{allowed_deductions};     }

TheAlternativeInterCapsApproachIsHarderToReadAndInParticularDoesn'tGeneralizeWellToALLCAPSCONSTANTS:

     FORM:     for my $taxForm (@taxFormSequence) {         my $notionalTaxPaid             = $taxForm->{reportedIncome} * $taxForm->{effectiveTaxRate};         next FORM if $notionalTaxPaid  < $MINASSESSABLE;         $totalPaid             += $notionalTaxPaid - $taxForm->{allowedDeductions};     }



Perl Best Practices
Perl Best Practices
ISBN: 0596001738
EAN: 2147483647
Year: 2004
Pages: 350
Authors: Damian Conway

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net