in reply to Plural variable naming (or not?)

I follow naming conventions roughly similar Juerd and simon.proctor.

Scalars should be singular, it really throws me off when they're not, $fields just really doesn't look right. Arrays should always be plural. Hashes on the other hand, I'm fairly indifferent about, but I tend to lean towards singular $field{name}. I think this looks a bit better than $fields{name} but it does depend somewhat on what it's being used for.

Replies are listed 'Best First'.
Re: Re: Plural variable naming (or not?)
by tachyon (Chancellor) on Mar 19, 2002 at 16:50 UTC

    Does this look right? Accessing a plural array for a singular element

    my @replies = ( 'so', 'plurals', { 'you' => 'think?' } ); my $answer = $replies[2]->{you}; print $answer;

      Actually, yes, it does :)

      It might only appear right to me because I've become accustomed to doing it that way. I do see your point, but I still find plural array names feel more natural than singular ones:

      my @reply = qw/a singular array name? how odd/; my $cannotnamethisreply = $reply[5]; print $cannotnamethisreply;

      Now that looks stranger to me than using a plural for the array name and a singular for the related scalar. I can understand either view though. :)

Re: Re: Plural variable naming (or not?)
by thelenm (Vicar) on Mar 19, 2002 at 23:53 UTC
    Scalars should be singular, it really throws me off when they're not, $fields just really doesn't look right.

    I agree with you on that one, although sometimes I will use a plural scalar if it's a named reference to an array, e.g.

    $fields = [1, 2, 3];
    That also helps me to remember that it's not a "normal" scalar, but that it's really referring to something plural.