*Naming Conventions*
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sun Jun 3 16:18:07 EDT 2007
In <MPG.20cd2ef21ffc11379896eb at news.individual.de>, Thorsten Kampe wrote:
> Recently I wrote this code and noticed that I was completely lost in
> giving these objects names to describe and distinguish them:
>
> for validanswer in validanswers:
> if myAnswers.myanswer in myAnswers.validAnswers[validanswer]:
> MyOptions['style'] = validanswer
Wow, I know you don't want to talk about "spelling conventions" but here
you are mixing many of them. :-)
I don't know if it makes sense for your code, but maybe you can move the
``if`` condition into the class of `myAnswer` as overloaded ``in``
operator. Then this can be written as:
for valid_answer in valid_answers:
if valid_answer in my_answers:
my_options['style'] = valid_answer
> The 'tips' I got through some postings or articles on the net are: if
> a function simply tests something and returns a boolean call it
>
> def is_<whatever_you_are_testing_for>():
> pass
The other typical boolean test prefix is 'has_'.
> like 'is_even'.
>
> Makes sense. The other thing I captured was to use something like
>
> def get_values():
>
> ... Makes sense, too, but aren't all functions getting something?
So you may reduce this to just `values()`. On the other hand there is the
convention to name functions and methods as verbs that are "doing"
something.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list