I will agree, variable naming is very important, but it
really depends upon scope. If i am writing a one-liner,
i'll use the fewest characters possible, such as $f, @f,
or %f. If i am writing a throw away script, i don't feel
quilty for using foo, bar, baz, and qux here and there.
If it is a script that i plan for others to use, i sit
and think very carefully about the names. If i am working
with a group, i will do my best to stick to whatever
standards they have agreed upon.
Coming from Java, i used to name my variables like
employeeRecord and thingWithNoName, but now i stick to the
convention of using all lower case and separating words
with the underscore - thing_with_no_name. This also keeps
me from chosing long names since i hate reaching for the
underscore key. ;)
When confronted with mental block on finding a good name,
if i can't think of one in 5 minutes or less, i will pick
something and move on. Leaving a comment that promises to
rename the variable reminds me of why i did so. I really
feel that names are important, but not so important as to
get stuck in rut over them. This is similar to listening to
someone's conversation when they pause for far too long
trying to find the right word, completely losing
their train of thought.
Final comment - plurals. tye finally convinced me to
avoid using plurals for arrays and hashes, because they
already indicate a colletion: @file, @line, %record. This keeps me from guessing between $file and @file, $record and
%record. This is also a new practice for me, so i sometimes
forget.
jeffa
Consistency is golden
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.