Variable Naming [was Re: [Israel.pm] catching $a, $b unnecessary my and maybe other things]

Yuval Yaari yuval at windax.com
Mon Jun 7 05:22:19 PDT 2004


>People should use an operating system that doesn't crash three times a day.
>
>People should use a standards-compliant browser that doesn't have more 
>security holes than Swiss cheese. (oh wait - most of them don't).
>
>The Technion should teach a shell that wasn't shown to be considered harmful, 
>and isn't loathed by any half-witted UNIX hacker. (oh wait - it doesn't).
>
>Seriously now, not all editors implement auto-completion, just as not all 
>editors have built-in functionality to read mail, browse the web or talk on 
>the IRC. (;-)) Auto-completion is not yet considered a feature that every 
>editor must have, much less a feature that all programmers use, or wish to 
>use. Maybe some years from now this situations will change, but at the 
>moment, I and many other people do not use auto-completion, or use editors 
>that do not.
>
>I don't think auto-completion is editor-bloat or creeping feuturism. It's a 
>useful feature. However, it's still the programmer's choice to use it or need 
>it. gvim, which I use daily, has many features that I don't utilize, even 
>though they may be useful. So is auto-completion.
>  
>
Your editor should be a mail, web and IRC client...
It should also translate your Perl code to morse code.
While these features exist in my editor, they are stupid and useless 
(the fact that I sometimes use them means that I'm stupid and useless...).
Auto-completion is neither useless nor stupid.
Vim can auto-complete, and it's the most basic feature for an editor, 
and it's a pure must.
It's very useful.

All editors have so many features that we don't use.
Don't compare M-x doctor to auto-completion (which again, is a 
life-saver and a must for all editors and I call programmers of the 
world to use it :)).

>>Your editor is your power tool.
>>
>>    
>>
>
>"power tool"... not again! A programmer's editor is one of his most commonly 
>used tools. Whether it is a "power" tool, is debatable. Some people can draw 
>well with a computer carying a host of very feature-ful, and sometimes very 
>costy, computer graphics programs. Others can draw very well by using a 
>pencil, or editing the SVG/EPS/whatever file directly. Would you call a 
>pencil a power tool?
>
>Similarly some people use Emacs or some complex IDE for their editing tasks, 
>while others are using joe, classic vi, or some other feature-impaired 
>editor. A code a programmer produces should be editable by all editors, not 
>just those that have particular features. (auto-completion in our case)
>  
>
I meant a power tool for programmers.
I can't think of another way to program, please open my eyes to your 
telepathic way of programming :)

>>Names should be 20 chars long, but should describe it.
>>    
>>
>
>This sentence does not make sense. It's probably:
>
>"Name should not be 20 chars long, but should describe it."
>
>If so, then I agree.
>  
>
My mistake. Was it this morning when I was really late for work (I got 
here at 9:30 at the end, not THAT bad)? :)

>>Also, if you find that your name isn't enough, but some comment near the
>>first decleration.
>>
>
>Did you mean "put some comment". Yes, you're right about that. Albeit comments 
>are not a substitute for meaningful variable names.
>  
>
Yes I did. Again, the late-for-work-excuse.
I agree, but they do come in handy most of the time.
I'll explain: I always use strict. It's in my editor's Perl template 
(when I create a .pl file, it's there).
So I always use "my" to declare variables.
If I find $VarThatIcantUnderstand then I just look for "my 
$VarThatIcantUnderstand" and check for the comment.
If both name isn't clear and no comments exist (or the comment isn't 
clear), I'm in troubles and I start with the digging which I hate.
Remember - always use clean names and comments (bad English doesn't 
count) - so I would still have hair when I reach 20 :)

>[...snip...]
><nod />
>  
>
Are you agreeing with the infamous 1 screen law?

>>Auto-completion is a must.
>>Not only because I'm lazy (I am, that's why I use Perl!) - but it makes a
>>lot of [even all] typos go away.
>>My editor auto-completes Perl functions aswell as already written words.
>>    
>>
>
>See, what I said earlier about auto-completion. And you can say that I'm lazy 
>enough to remember another keystroke, or to try to enable it in gvim. I'm 
>also much less reluctant to switch to a different editor, because I'm used to 
>gvim, (in my particular, highly non-conventional configuration).
>
>  
>
NO - gvim has it, I've seen it with my own 2 eyes :)
Though switching editors should come to your mind... (just kidding - 
even use notepad if you're used it...)

>As for typos, "use strict" catches most of them. I sometimes confuse between 
>two distinct variables. (with completely distinct names) In this case, 
>neither auto-completion, nor strict help.
>  
>
In this case, M-x perldb works well.
Does the Perl debugger integrate to your editor? I think it's important 
too. Really.

>>>Generally, using abbreviations for variable names is a good idea. They
>>>make  the code flow better.
>>>      
>>>
>>I disagree.
>>Maybe if you put a comment on the 1st decleration.
>>
>>    
>>
>
>Note that I meant abbreviations, not acronyms. By this I mean using "num" 
>instead of "number", "perm" instead of "permutations", etc. As for acronyms 
>(="rashey teivoth"), they are usually Evil as variable names, unless it's a 
>well-established one. You can use "$tcp_port" instead of 
>"$transfer_control_proto_port" for example.
>  
>
I thought you mean acronyms (which I know what they are...).
As for acronyms, as long as they exist in www.acronymfinder.com - I 
think it's ok to use them, though personally, I wouldn't.
TCP and such are exceptions, of course.

>>That's not just russian - you should know by now what these things mean :)
>>
>
>I have no idea what "Naxuy Suka Blat" means.
>  
>
Curses in Russian.
I know what "Naxuy", "Suka" and "Blat" mean, but together I don't think 
they form anything logical.

>>Of course, and I was just kidding.
>>
>
>Heh heh.
>/me taking jokes too seriously as always
>  
>
We all do sometimes.

>>I'm going to be late for work if I don't stop reading mail in the
>>morning...
>>
>Heh heh. I read some of this discussion, before I needed to go (walk, 
>actually) to a job interview in the morning. I was still able to arrive about 
>10 minutes early.
>  
>
See? I was late for work so I was trying to type as fast as I can.
Reading mail before work is a bad idea.

I hope the interview went well, good luck.


  --Yuval




More information about the Perl mailing list