Hungarian Notation

Carl Banks pavlovevidence at gmail.com
Tue May 27 03:23:58 EDT 2008


On May 27, 2:37 am, Paul McGuire <pt... at austin.rr.com> wrote:
> On May 27, 12:28 am, "inhahe" <inh... at gmail.com> wrote:
>
> > Does anybody know of a list for canonical prefixes to use for hungarian
> > notation in Python?  Not that I plan to name all my variables with hungarian notation, but just for when it's appropriate.
>
> You are likely to get some links to PEP 8 for coding style and naming
> conventions, but it turns out PEP 8 doesn't really say yay or nay on
> the Hungarian notation topic.
>
> My own knee-jerk reaction was "Hungarian Notation Bad!" and googling
> about for "python hungarian notation" led me through some like-minded
> sites.  But I also found this entry on Joel Spolky's site (http://www.joelonsoftware.com/printerFriendly/articles/Wrong.html), that
> warns against tarring all Hungarian-type notations with the same
> brush.

The name of a variable is a valuable resource.  There are all kinds of
things you can encode in it, but you have to choose only one or two.
The most important information is what it is (e.g., box), or what it's
archetype is (i, for a counter variable).  Pretty much all names
should contain one of these two.  Second most important are
discriminators such as a description (red_box), usage (shoebox), or
circumstance (next_box).

But sometimes other things are important enough to warrant addition to
the name.  Type usually isn't one of them, but there are times when
it's helpful to know.  But then, I'm not sure I would call it
"Hungarian notation" to add ad hoc type information to a few of names
here and there.

One convention I have for myself is to use x<elementname> for elements
when I'm using ElementTree, but the reason is pragmatic: I'm creating
objects that have the same name as the elements.


> So with that article in mind, I'd have to ask, what do you mean by
> "appropriate"?

It seems like OP wanted to disambiguate two objects based on type,
which seems reasonable to me.  Sometimes you want to have side-by-side
represenations of something where type is the main difference, in
which case there's no reason type shouldn't be added to the name.


Carl Banks



More information about the Python-list mailing list