Perl Style: Length of Variable Names

  • `The appropriate length of a name is directly proportional to the size of its scope.’ –Mark-Jason Dominus
  • Length of identifiers is not a virtue; clarity is. Don’t write this:

        for ($index = 0; $index < @$array_pointer; $index++) {
             $array_pointer->[$index] += 2;

    When you should write:

        for ($i = 0; $i < @$ap; $i++) {
             $ap->[$i] += 2;

    (One could argue for a better name than $ap, though. Or not.)

  • Global variables deserve longer names than local ones, because their context is hard to see. For example, %State_Table is a program global, but $func might be a local state pointer.

        foreach $func (values %State_Table) { ... }

Forward to Parallelism
Back to On the Naming of Names (Content)
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.



Something wrong with this article? Help us out by opening an issue or pull request on GitHub