Dnia 17-07-2010 o 02:57:46 Steven D'Aprano <st...@pearwood.info>
napisaĆ(a):
On Sat, 17 Jul 2010 05:44:07 am pk wrote:
In general, the shorter and more descriptive a variable name is,
the better.
That's a generalisation that is contradictory. Short works against
descriptive. Compare:
Well, yes I agree. I've chosen a wrong word in this context. By writing
"descriptive" I meant that it should be as *informative, full of meaning
and precision* as possible; and at the same time as concise as possible.
The word "meaningful" would probably be appropriate here.
Achieving the two goals can sometimes be hard and if there're no or few
comments, a program - especially a longer one - can be difficult to read
and understand. Fortunately, Python is not Perl (with its unnecessarily
rich syntax, terseness, names containing punctuation and special
characters), so in most cases it is easy to see what is going on - at
least I think so.
Wow, that's very general what I've just written and very much a repetition
(rephrasing) of your words, but I wanted to be clear.
Regards,
Piotr
n # nice and short
number_of_widgets_ordered # nice and descriptive, if a bit wordy
widgets_ordered # a happy medium
Which is appropriate depends on the context. Generally, descriptive
names are self-documenting and are to be preferred, but it is possible
to overdo it:
def multiply_two_numbers_and_add_one(
first_number_to_multiply_by, second_number_to_multiply_by
):
return first_number_to_multiply_by*second_number_to_multiply_by + 1
The more terse version is simple enough to understand:
def mult_plus_one(x, y):
return x*y + 1
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor