Perl: the Markov chain saw | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Appending _ref doesn't seem particularly sensible to me, though I haven't got my hands on the book yet to see the full rationale. But my personal style has been evolving to use fewer and fewer real arrays and hashes, and the potential for mishap disappears if everything is a ref (or at least a scalar). As for plural names, I'm pretty inconsistent: I can argue it both ways in my head, and frequently do. If $item->[$index] looks right then if (@$item) { ... } looks wrong, and vice versa when the name is plural. The only sense I can see in picking a different convention for arrays versus hashes, though, is an assumption about the style of use: that for a hash the primary use will be to dereference an element, while for an array the primary use will be to act on the collection as a whole. But even if true, I'm not convinced it's necessarily a valid distinction: the question is whether you think of it as a collection, and whether in that respect you think of arrays and hashes differently - and if you do, I think you probably shouldn't. :) I think though that the intention of the book is to give a simple and consistent set of rules to people who are not inclined, or able, to go through the same tortuous thinking process for themselves. For those that are so inclined, it is rather food for thought, and another data set to add to the collection (sic). Note that changes due in perl6 may alter the balance substantially - I've fallen behind with the design, but I think it was moving in the direction of having @array and %hash be no more than syntactic sugar for a ref in a real scalar; similarly, Larry was talking about an array as "just a hash with a constraint on the keys", implying that all the rest is just under-the-hood optimisation (though I'm not sure if that thought ended up affecting the syntax at all). Hugo In reply to Re: Perl Best Practices for naming variables
by hv
|
|