Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Perl Best Practices for naming variables

by hv (Parson)
on Aug 07, 2005 at 00:05 UTC ( #481575=note: print w/replies, xml ) Need Help??

in reply to Perl Best Practices for naming variables

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).


Replies are listed 'Best First'.
Re^2: Perl Best Practices for naming variables
by creamygoodness (Curate) on Aug 07, 2005 at 01:19 UTC
    For all collaborative coding efforts, and CPAN code especially, there are benefits to adhering to standard practices: other people find it easier to grok, hack, debug, or contribute. The first priority is self-consistency, but the closer the ruleset is to a ruleset everyone is already familiar with, the greater the advantage.

    I'll certainly reserve the right to redefine a rule or two, but for the most part I really like (and already practice many of) Damian's recommendations, and would be happy to see them become a de-facto standard, as Andy Lester has suggested they may. It's worth it to me to struggle with the ones that strike me as odd. Spinach for thought.

    Marvin Humphrey
    Rectangular Research

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://481575]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2018-01-23 11:13 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (243 votes). Check out past polls.