Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Plural variable naming (or not?)

by cjf (Parson)
on Mar 19, 2002 at 14:53 UTC ( [id://152735]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://152735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-18 01:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found