variable naming...

Alex Martelli aleaxit at yahoo.com
Thu Apr 26 14:17:20 EDT 2001


"Owen F. Ransen" <ransen_spam_me_not at nemo.it> wrote in message
news:3ae934d3.2582143 at news.newsguy.com...
> Gonna get a lot of flames for this one maybe...
>
> In C I am used to using the notation where the first bit
> of the name tells you the type of the variable:

It's often called "Hungarian Notation", and, as I guess
you know, pretty controversial in many languages.


> int iNumFlames ;  // integer
> char szFlame[MAX_CHARS] ; // zero terminated string
>
> and so on. I presume this is not reccommended in Python?
> I've found it very helpful in C...

If your code is for your own use rather than for publication,
and you find _whatever_ notation or naming convention to
be useful to you, who's to say otherwise?

Among the reasons one might prefer to avoid it in
Python (even if one liked it for C) is that a single
reference (including named ones, such as variables
and attributes) often can usefully take on different
types -- naming it for a type could then be misleading
rather than helpful.  There is also such a huge variety
of "types" (particularly if you consider each class to
be a different "type" -- not strictly true, but...) in
frequent use in Python that trying to develop usable
type-based names may prove problematic.


> Is there an "official" or "semi-official" style, like when
> to use lowercase and uppercase and mixed?

Leading underscores and double underscores have
language-specified meanings ('private', or 'magic
special thing' for double leading & trailing _'s).  Apart
from that, there IS useful advice, including an
essay by Guido detailing his preferred coding
style, on www.python.org (sorry, no precise URL
at hand), but this may not be even "semi-official".


Alex







More information about the Python-list mailing list