Monks,
I am just writing down some thought here below. If you want to take it serious, be my guest... ;-)
I have been wondering on the naming of variables. Not so much what to call them (Non ambigious, descriptive, not to long and to to short) but wheter to use plurals for different types of variables.
An array holds a list of variable values of the same context, say : database fields. The context of the program could lead us to suspect that all is database related, and thus you choose the name fields. This is logic. Now we come to hashes. A hash is nothing more then a noble array, but the context of the hash could be much wider. If you want a hash with database fields, and a context specifier in the value of each key, would we then call the hash 'field' or 'fields'. I agree that the entire hash contains fields, and it should thus be plural, but when we put the hash to use, field is more appropriate. (eg:
$fields{ID} or
$field{ID}).
Hmm... Now the ideal plural for the array is no longer that logic, cause when I start to use the array litteraly in my code (
$fields[0]) and there is but one thing in that item, the naming has suddenly become ambigious.
It seems that one has to think deeper on his variable naming for list storing variables (hash or array) then seems apparent. If you store field names in an array, and you wish to use the values distinct in your code, you must call the array @field, cause it makes more sence. If you wish to apply the entire list (eg:
foreach my $field (@fields) { ... }) You must name you array @fields.
With the use of hashes I think avoiding plurals in naming them is best, since you won't just use the keys of a hash for lists in foreach, you will actualy dive deeper, and plurals will (mostly) become ambigious and non-descriptive...
*sigh*
UPDATE : Saw the flaw,
ChOas pointed out, and took over
simon.proctor's syntax...
er formait hyarya.
"Field experience is something you don't
get until just after you need it."
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, details, 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, summary, 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.