markup.py - 1.2 - an HTML/XML generator

Daniel Nogradi nogradi at gmail.com
Tue Apr 4 06:05:42 EDT 2006


> > $ pwd
> > /usr/lib/python2.4/site-packages
> > $ grep -re klass . | wc -l
> > 274
> > $ grep -re class_ . | wc -l
> > 897
>
> How many of those "class_" instances are really just substrings of
> "__class__" and "class_name" and such?  On my machine, I see a handful
> in the standard library, and _none_ in site-packages (which has only
> 1709 .py files, mind you).
>
> > For me that's enough. "class_" is used at least three times more than
> > "klass". Besides, as Scott pointed out, "class_" is prefered by the
> > guidelines too.
>
> Actually what he posted explicitly states that "cls" is preferred.
> Following that it says that one should considering appending _ if the
> name conflicts with a keyword (and one can assume it means "for all
> keywords other than class").
>
> >>`cls`, at least, is more commonly used within
> >>Python itself (e.g., classmethods).
> >
> > Yes. cls wouldn't be a good choice. But class_ is. Or maybe even
> > css_class. But klass isn't.
>
> As has been pointed out, klass has a fairly established tradition of
> use.  (I happen to agree with the PEP and use "cls" exclusively for such
> things, and do agree that "klass" is crude.)
>



It seems there are 3 competing versions:

(1) cls
(2) class_
(3) klass

(1) is encouraged by PEP-8 for class methods
(2) is encouraged by the same PEP for keyword arguments if there aren't synonyms
     available
(3) is used widely and doesn't seem ugly to anyone whose language uses
'k' for the
     first sound in the English pronounciation of the word 'class'.
And it happens in
     English too, although usually not at the beginning of the word,
like 'quick', 'break',
     etc.

And there is an additional point in PEP-8, namely one should avoid
spelling corruption, so 'print_' is preferred instead of 'prnt' but
the best is to invent a synonym. Now the question is whether 'klass'
counts as a spelling corruption or it is more like a synonym. I
thought it's not a corruption that's why I chose to use it (I must
also admit I haven't even thought about (1) or (2) at all or PEP-8 to
begin with). So I guess 'klass' is okay, but I'm open to other
suggestions, I have only problems with 'class_' as I usually dislike
non-alphabetical characters unless they are absolutely necessary.

Any further thoughts on this?



More information about the Python-list mailing list