Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: About the use of the plural form for the name of variables

by Anonymous Monk
on Nov 08, 2012 at 12:00 UTC ( #1002882=note: print w/replies, xml ) Need Help??


in reply to About the use of the plural form for the name of variables

Perl:  for my $friend ( @friend ) ...

English: for my $friend of array of friends

English: for my $friend from friend array

English: for my $friend

Hmm, Perl Best Practices for naming variables says use %vegetable in the singular

I think great, but its not a table, use %veg :)

Replies are listed 'Best First'.
Re^2: About the use of the plural form for the name of variables (Perl Best Practices best practices)
by tye (Sage) on Nov 08, 2012 at 15:17 UTC
    I think great, but its not a table, use %veg :)

    Excellent point.

    Hmm, Perl Best Practices for naming variables says use %vegetable in the singular

    This made me chuckle. It lead to me imagining Dr. Conway digging his own grave just so he could roll over in it. I know he went to a lot of effort to provide justifications for each "rule" he included. And I know he went to a lot of effort to document that his intent was not to have people blindly parroting rules without considering the justifications and whether or not each applied to their particular environment / situation / style, etc.

    And yet, the vast majority of references to Perl Best Practices that I see are cases of people blindly parroting rules from it. (Perl::Critic is perhaps the most egregious example of this.)

    But I give you points for providing a link. The link did include a justification:

    Damian also recommends naming hashes in the singular, the idea being that individual accesses seem more natural: $vegetable{spinach}.

    Note that I already said that I don't mind having the pluralizing 's' (or other suffix) being immediately followed by a "one of" syntax element (like [1] or {spinach}). They end up right next to each other and so I find no confusion results.

    But I also find $vegetable{spinach} to be an example of a lousy use of a variable name. What are you tracking about vegetables, including spinach? Which of the things that you are tracking do I get back from $vegetable{spinach} ? I guess you might have a bunch of Whatever::Vegetable objects, which would make the name less bad.

    I've seen a recommendation to use prepositions in the names of hash variables. For example, my %vegetable_obj_from_name;. But I realize that I relatively rarely have multiple hashes indexing into the same space of values. So I'm more likely to go with your advice of "It is a variable of limited scope, give it a name that is somewhat mnemonic but also short and thus faster to type and even to read... like %veg".

    Thanks for the reality check and for the chuckle. (:

    - tye        

      The reasoning from your example is obvious; Google only returns "vegetable hash" recipes, but not "vegetables hash" recipes. :-P
      A Monk aims to give answers to those who have none, and to learn from those who know more.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002882]
help
Chatterbox?
[stevieb]: It seems as though some Strawberry Perl downloads have incorrect checksums all of a sudden. Could someone please download http://strawberryp erl.com/download/5 .12.3.0/strawberry -perl-5.12.3.0- portable.zip and do an sha1sum on...
[stevieb]: ...it? I'm getting 309ad7a9ba74614fcd 0c65bff7ea4400c10f a92f, but the http://strawberryp erl.com/releases. html states 0e267fc2cf5a16126d a6f9520cc7664db63d 2b57 and want to ensure it's not just me
[stevieb]: ...or the proper download link and release page even...
[pryrt]: da39a3ee5e6b4b0d32 55bfef95601890afd8 0709 *strawberry-perl-5 .12.3.0-portable. zip
[pryrt]: matches neither. :-)
[stevieb]: wtf!? lol
[stevieb]: I'm checking some other versions. This is a little frightening
[pryrt]: Sorry, my bad: it was't done downloading when I did the sha1sum... now I match your 309ad... value

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2017-03-29 20:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (353 votes). Check out past polls.