Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Perl Best Practices for naming variables

by ff (Hermit)
on Dec 20, 2006 at 12:03 UTC ( #590895=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl Best Practices for naming variables
in thread Perl Best Practices for naming variables

I smiled when I came upon the '_ref' suggestion, recognizing it as a practice I already followed, sort of. Like you, I don't need the 'ef' part of that tag chewing up valuable line space and/or adding clutter. However, rather than just stopping at '_r', I DO like inserting an extra character to indicate the kind of reference I expect to be referencing. As in:
_ar for array ref _hr for hash ref _xr for code ref _sr for scalar ref
The program I'm writing has grown to be many lines and I prefer as much clarity as possible when I reread sections of it. If helps document my intentions which helps when refactoring. And with all the subroutines I end up inventing, it makes for a clear set of expectations of what variables should be passed to the subroutine without having to use prototypes.
sub foo { my ( $camels_ar, $votes_hr, $count_mechanism_xr, ) = @_;
Frankly, I wish more books that teach Perl would use this approach because as the learner, it's hard enough trying to understand some new idea without having to fight through the additional ambiguity of "now what's in this variable and why is it written up that way?"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://590895]
help
Chatterbox?
[marto]: icy here today, snow on the hills
[Corion]: Oh yes, Friday!
[Corion]: Last day at $work before 3 weeks of vacation (well, not that I'd be really travelling, but no-work-time ;) )
[robby_dobby]: marto: yeah, I'd eventually visit Glasgow some day - just to visit the home town of GHC :-)
[robby_dobby]: Corion: Oh, that's awesome! Your timing is perfect enough to see all hell break loose when you get back at work :P
[marto]: well, let me know in advance, I'll buy you a pint :)
[Corion]: robby_dobby: No, I'm returning in the second workweek of January. The main hectic parts are in the first days after the start of the new year
[robby_dobby]: marto: and, I'm not sure I'd be around here long enough for YAPC::EU
[marto]: Corion nice, what are you plans for Christmas?

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-12-15 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (431 votes). Check out past polls.

    Notices?