3.10. Utility Subroutines
A utility subroutine exists only to simplify the implementation of a module or class. It is never supposed to be exported from its module, nor ever to be used in client code. Always use an underscore as the first "letter" of any utility subroutine's name. A leading underscore is ugly and unusual and reserved (by ancient C/Unix convention) for non-public components of a system. The presence of a leading underscore in a subroutine call makes it immediately obvious when part of the implementation has been mistaken for part of the interface. For example, if you had a function fib( ) for computing Fibonacci numbers[*] (like the one shown in Example 3-1), then it would be an error to call:
print "Fibonacci($n) = ", _find_fib($n), "\n"; because _find_fib( ) doesn't return a useful value. You almost certainly wanted: print "Fibonacci($n) = ", fib($n), "\n"; By naming _find_fib( )with an initial underscore, the call to it stands out far more clearly, and the misuse is brought immediately to the attention of anyone familiar with the convention. Example 3-1. Iterative on-demand Fibonacci computations |