Naming Conventions, Where's the Convention Waldo?
News123
news1234 at free.fr
Sun Jul 11 09:46:40 EDT 2010
Andre Alexander Bell wrote:
> On 07/11/2010 10:30 AM, rantingrick wrote:
>>> So, it is not a disadvantage that the functions you listed above are
>>> named in this way. In the contrary, it is an advantage, as it keeps
>>> newcomers from using stupid variable names.
>> "int" for an Integer is stupid?
>> "list" for a List is stupid?
>> "str" for a String is stupid?
>>
>> What am i missing?
>
> You are missing (from PEP 8):
>
> --- 8< --- 8< ---
> Class Names
>
> Almost without exception, class names use the CapWords convention.
> Classes for internal use have a leading underscore in addition.
>
> --- 8< --- 8< ---
>
> You may want to think of list, int, str, object, ... as classes that
> don't follow this advice with their class name.
>
> But besides that, shouldn't a variable name reflect it's purpose instead
> of it's type? E.g.
hm, well sometimes I do write generic functions, that do something with
a list or a string or an int.
However a simple way around this is to use following naming style.
to replace
def process_list(list):
dostuff_with(list)
with
def process_list(alist):
dostuff_with(alist)
or with
def process_list(a_list):
dostuff_with(a_list)
I must admit, that I have still problems
to not use the variables range or id
More information about the Python-list
mailing list