Context in variable naming.

schwern on 2008-09-06T07:49:53

I'm going through a patch, and came across this

=head3 _sort_pairs

my @pairs = _sort_pairs($sort_sub, \%hash); Sorts the pairs of a hash based on keys ordered according to C<$sort_sub>.

=end private

=cut

sub _sort_pairs { my $k_sort = shift; # a CODE my $hash = shift; # a HASH


Aside from the CS freshman commenting, anything called "$hash" or "$array" or "$list" is a red flag. Consider the context when naming a variable. The subroutine is called "sort_pairs" to which one gives pairs. What's a good name for the variable containing those pairs? Yes, $pairs.

(Apologies to the patch submitter for being the target of my nit-picking).