Naming Conventions, Where's the Convention Waldo?

Neil Cerutti neilc at norwich.edu
Tue Jul 13 11:18:13 EDT 2010


On 2010-07-12, Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
> On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote:
>
>> On Jul 11, 3:03??am, "G??nther Dietrich" <gd.use... at spamfence.net> 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?
>
> If you're going to use generic names, why type three or four letters when 
> one will do?
>
> i, j, k, m, n, p, q for ints.
> L, a, b, x for lists
> s, t, a, b for strings.
>
> If you don't want to use generic names, then int, list, str are useless 
> because they don't mean anything. You need something like:
>
> count_of_widgets
> list_of_widgets
> description

def map(function, list):
   # etc.

It's a slight annoyance, nothing more.

In the data I deal with, I get annoyed at needing to write
student_id instead of id, but it's not a huge issue. The big
consolation is that Python really doesn't care if I happen to
shadow a builtin name that I've never heard of. I forget, and use
id as a variable all the time, and nothing bad happens to me,
because I don't need the builtin function.

To see a really odd example of a similar name clash, create a tab
separated values file with a header line starting with ID (I get
lots of them in my work), and then open it with Excel (I don't
know which version has the most bizarre error message).

-- 
Neil Cerutti



More information about the Python-list mailing list