Previous Page
Next Page

3.8. Ambiguous Abbreviations

Abbreviate only when the meaning remains unambiguous.

Well-chosen abbreviations can improve the readability of code by reducing the length of identifiers, which can then be recognized as a single visual chunk. Abbreviation is, in effect, a form of visual hashing.

Unfortunately, as with most other hashing schemes, abbreviation suffers from the problem of collisions. When a single abbreviation could be the shortened form of two or more common words, the few characters saved by abbreviating will be paid for over and over again in time lost deciphering the resulting code

    $term_val      # terminal value or termination valid?
        = $temp    # temperature or temporary?
          * $dev;  # device or deviation?

On the other hand, abbreviating down to even a single character can occasionally be appropriate:


    
# Run the standard dynamic and kinematic calculations...
$a = $f / $m; $v = $u + $a*$t; $s = $u*$t + 0.5*$a*$t**2;

The standard single letter iterator variables$i, $j, $k, $n, $x, $y, $zare also often acceptable in nested loops, especially when the indices are coordinates of some kind:


    sub swap_domain_and_range_of {
        my ($table_ref) = @_;

        my @pivotted_table;
        for my $x (0..$#{$table_ref}) {
            for my $y (0..$#{$table_ref->[$x]}) {
                $pivotted_table[$y][$x] = $table_ref->[$x][$y];
            }
        }

        return \@pivotted_table;
    }

    Previous Page
    Next Page