Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Using $a and $b for sort

by jbert (Priest)
on Jan 03, 2008 at 12:01 UTC ( #660176=note: print w/ replies, xml ) Need Help??


in reply to Using $a and $b for sort

Avoiding $a and $b in perl is particularly good advice (due to the overlap with the sort magic variables).

But it's also a good idea to avoid them since they aren't meaningful names. I think one of the most important parts of writing code is choosing good names for variables (and functions, and all name-able things). I don't mean needlessly long names, but appropriate names (name length should in general be loosely proportional to variable scope - if that gives you long names you want smaller scope for your variables).

Yes, you have to stop and think about a good name, but it makes the code much more readable. Compare: $page->render(); with $tmp->do_it().

It's also important to change names if you change the code, so they stay accurate. (e.g. change a variable from $employee to $person if you make a routine more general).


Comment on Re: Using $a and $b for sort
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://660176]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2015-07-08 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (94 votes), past polls