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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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        


In reply to Re^2: About the use of the plural form for the name of variables (Perl Best Practices best practices) by tye
in thread About the use of the plural form for the name of variables by grondilu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (6)
    As of 2014-12-20 06:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (95 votes), past polls