473,288 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Hungarian Notation

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.

Jun 27 '08 #1
12 3558
inhahe 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.
I used simple Hungarian notation when I started programming in Python
(e.g. "s" for strings, "l" for lists, "d" for dictionaries). As my
programming style became more "Pythonic" and I chose better variable
names, I stopped using Hungarian notation.

YMMV.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #2
On May 27, 12:28*am, "inhahe" <inh...@gmail.comwrote:
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://
http://www.joelonsoftware.com/printe...es/Wrong.html), that
warns against tarring all Hungarian-type notations with the same
brush.

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

-- Paul
Jun 27 '08 #3
Well, I just need it once in a while. Actually now is the only time I
remember. The last time what I needed was a file name extension. I want a
string called headers, but I want to derive a dict from it, also called
headers. So I figured the string would be called strHeaders, and the dict,
dctHeaders probably, but when a precedent for something like that exists, I
like to use it.

"Kam-Hung Soh" <ka*********@gmail.comwrote in message
news:ma***************************************@pyt hon.org...
inhahe 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.

I used simple Hungarian notation when I started programming in Python
(e.g. "s" for strings, "l" for lists, "d" for dictionaries). As my
programming style became more "Pythonic" and I chose better variable
names, I stopped using Hungarian notation.

YMMV.

--
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>

Jun 27 '08 #4
On May 27, 2:42 am, "inhahe" <inh...@gmail.comwrote:
Well, I just need it once in a while. Actually now is the only time I
remember. The last time what I needed was a file name extension. I want a
string called headers, but I want to derive a dict from it, also called
headers. So I figured the string would be called strHeaders, and the dict,
dctHeaders probably, but when a precedent for something like that exists, I
like to use it.

I doubt there's anything canonical since Python community, PEP 8, and
Python's dynamic typing all discourage its use. I would venture to
say that the community would frown upon names such as "strHeaders"
since they don't agree with the naming conventions in PEP 8. Instead,
use "str_headers" and "dict_headers". Better yet, use "headers_str"
and "headers_dict". Put the less important information last.
Carl Banks
Jun 27 '08 #5
On May 27, 2:37 am, Paul McGuire <pt...@austin.rr.comwrote:
On May 27, 12:28 am, "inhahe" <inh...@gmail.comwrote:
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/printe...es/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<elementnamefor 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
Jun 27 '08 #6
On May 27, 7:42 am, "inhahe" <inh...@gmail.comwrote:
Well, I just need it once in a while. Actually now is the only time I
remember. The last time what I needed was a file name extension. I want a
string called headers, but I want to derive a dict from it, also called
headers. So I figured the string would be called strHeaders, and the dict,
dctHeaders probably, but when a precedent for something like that exists, I
like to use it.

"Kam-Hung Soh" <kamhung....@gmail.comwrote in message
I have a my own sometime used convention od using dict names that
mirror
what is being mapped to what, so a dict mapping headers to body might
be called head2body, in general a mapping from x to y I might call
x2y.

- Paddy.
Jun 27 '08 #7

"Paul McGuire" <pt***@austin.rr.comwrote in message
news:74**********************************@8g2000hs e.googlegroups.com...
On May 27, 12:28 am, "inhahe" <inh...@gmail.comwrote:

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://
http://www.joelonsoftware.com/printe...es/Wrong.html), that
warns against tarring all Hungarian-type notations with the same
brush.

Wow, that was fascinating. I had no idea Hungarian notation originally
didn't mean to prefix the object type!
Jun 27 '08 #8
On May 27, 3:43 am, Paddy <paddy3...@googlemail.comwrote:
On May 27, 7:42 am, "inhahe" <inh...@gmail.comwrote:
Well, I just need it once in a while. Actually now is the only time I
remember. The last time what I needed was a file name extension. I want a
string called headers, but I want to derive a dict from it, also called
headers. So I figured the string would be called strHeaders, and the dict,
dctHeaders probably, but when a precedent for something like that exists, I
like to use it.
"Kam-Hung Soh" <kamhung....@gmail.comwrote in message

I have a my own sometime used convention od using dict names that
mirror
what is being mapped to what, so a dict mapping headers to body might
be called head2body, in general a mapping from x to y I might call
x2y.
I use the same convention, though it's less than ideal if x or y
consist of more than one word (typically joined with underscore), e.g.
"value2row_id" or if the values are also dicts
("category2value2instances").

George
Jun 27 '08 #9
On May 27, 12:28*am, "inhahe" <inh...@gmail.comwrote:
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.
pnWe vUse adjHungarian nNotation prepAt nWork, conjAnd pnI vauxDont
vLike pnIt advVery advMuch. conjSo pnI vAvoid pnIt prepIn nPython.
Jun 27 '08 #10
In article
<46**********************************@2g2000hsn.go oglegroups.com>,
Dan Bishop <da*****@yahoo.comwrote:
On May 27, 12:28*am, "inhahe" <inh...@gmail.comwrote:
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.

pnWe vUse adjHungarian nNotation prepAt nWork, conjAnd pnI vauxDont
vLike pnIt advVery advMuch. conjSo pnI vAvoid pnIt prepIn nPython.
HAHAHAHAHAHA! Beautifully done. Next time I need to diagram a sentence
I will come to you. You're the man. :-)

--
-- Lou Pecora
Jun 27 '08 #11
Dan Bishop a écrit :
On May 27, 12:28 am, "inhahe" <inh...@gmail.comwrote:
>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.

pnWe vUse adjHungarian nNotation prepAt nWork, conjAnd pnI vauxDont
vLike pnIt advVery advMuch. conjSo pnI vAvoid pnIt prepIn nPython.
Mouarf ! Keyboard ! (and +1 QOTW BTW)
Jun 27 '08 #12
Lie
On May 27, 12:28*pm, "inhahe" <inh...@gmail.comwrote:
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.
If it was me, I'd use an empty-defined class:

class Fake(object):
pass

data = 'headinfo=trash;headtrash=info'
Header = Fake()
Header.Str = data
Header.Dict = parse(data)

it saves name if it's important (alternatively, you may also use a
dict or a tuple/list to store the string/dict pair).
But using Fake class just like that is difficult to work with if I
need to "write" to the data (not read only) and synchronizes the data,
in that case, it's easy to extend the Fake Class:

class Fake(object):
def __init__(self, data):
self.data = parse(data)

def toStr(self):
return str(self.data)
def fromStr(self, s):
self.data = parse(s)
Str = property(toStr, fromStr)

def toDict(self):
return self.data
def fromDict(self, s):
self.data = s
Dict = property(toDict, fromDict)

you might go as far as overriding __str__ and __repr__ as appropriate.
Jun 27 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Phill | last post by:
Does anyone know the reasoning for Microsoft abandoning Hungarina Notation in C#? I have found it very usefull in C++. I like this style: constant: MY_CONSTANT methos: myMethod() class: ...
66
by: CMM | last post by:
So after three years of working in .NET and stubbornly holding on to my old hungarian notation practices--- I resolved to try to rid myself of the habit. Man, I gotta say that it is liberating!!! I...
14
by: Ronald S. Cook | last post by:
I've been weaning myself off of Hungarian notation because that's what Microsoft is telling me to do, and I want to be a good little MS developer. But things keep coming up that make me miss my...
18
by: dom.k.black | last post by:
I am looking at starting a new piece of work for a company who are heavily into hungarian notation for C coding. Any killer arguments for NOT carrying this terrible practice forward into new C++...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.