Hungarian Notation
Michael Mabin
d3vvnull at gmail.com
Fri May 30 08:04:27 EDT 2008
Variable names should have prefixes or suffixes (as I prefer) that represent
the "kind" of data they represent rather than the data type itself.
For example account_bal_am, order_qt, line_ct, first_nm. Where am is
amount, qt is quantity and ct is count. Coding standards could impose rules
on datatypes that should be used for these kinds: am (amount) is a currency
field and should be represented by decimal values. qt (quantity) is a long,
nm a string and so on.
On Fri, May 30, 2008 at 3:31 AM, Lie <Lie.1296 at gmail.com> wrote:
> On May 27, 12:28 pm, "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.
>
> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
| _ | * | _ |
| _ | _ | * |
| * | * | * |
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080530/6e003a93/attachment-0001.html>
More information about the Python-list
mailing list