[Tutor] always declaring variables

Jerry Jorgenson jerry@j3iss.com
Sat Feb 15 09:42:01 2003


On Sat, 15 Feb 2003 12:32:05 +0100
Charlie Clark <charlie@begeistert.org> wrote:

> The consensus seems to be use names that mean something and relate to
> each other; ie. "octet" and "restofline" are IMHO not a good pair. But I
> don't 

In this case, I'm reading several host files, I only care about the
ip-address and it's octets in the begining of the line. The remainder
really is "the rest of the line", and nothing happens to it except that it
gets printed later, so it makes a great deal of sense in this context.

> think commenting variable names is helpful anyway; I for one constantly 
> recycle names or transform variables which easily breaks such
> declarations. I also now make extensive use of locally scoped variables
> where it makes sense for me: orthogonally similar functions.
> 
> I think it's more important to explain what particular parts are going
> to try to do, ie. a brief commentary at the start of the module as to
> what it aims to do and comments, descriptions of all functions, class
> methods. Functions can carry an optional description and can easily be
> queried as to what variables they expect. More than that doesn't tend to
> get maintained anyway and it's optimistic at best or naive at worst to
> expect it.

Yes, I put comments in as you suggest (in fact, I think I mention this in
an earlier post), but since this is a Python newsgroup, I've tried to keep
the Perl examples to a minimum just to illustrate the point that I was
making (if I was a better Python programmer, then I would post some Python
examples, but hey, that's why I'm in this newsgroup). 

Generally, I don't find a problem with maintaining the variable comments,
because if you change the meaning of the variables, you are changing the
fuction and likely using new variable names anyway. What I have noticed is
that my co-workers like to work on my code, they say it's much easier for
them to modify. As usual YMMV. (I've always hated the $i $j $k kind of
variables with just an explaination, of what the code segment does, I'd
much rather see $widgetCount, $productionLimit, $costConstant with a
definition of what a widget is, what production you are talking about, and
what makes up the cost).


Jerry

-- 
Jerry Jorgenson
jerry@j3iss.com
http://www.j3iss.com/