Do I always have to write "self." ?

Samuel A. Falvo II kc5tja at garnet.armored.net
Sun Apr 30 20:19:53 EDT 2000


In article <B53241E5.580F%abrahams at mediaone.net>, Dave Abrahams wrote:
>As Simonyi, the author of the Hungarian notation concept writes, "the basic
>idea is to name all quantities by their types". If you are naming quantities
>by their interface, you are taking a step away from Hungarian. Do as I do,
>naming quantities by their *role*, and you have taken a long leap away from
>Hungarian.

If an object exposes a particular interface, then it is guaranteed to be of
a particular type.  Defining parameters in terms of their roles is
analogous.  Again, I just don't see the distinction.

>I can see how it might help to name a variable by its interface, especially
>in Python if you don't write comments. But: do you write listDogs, tupleDogs
>or sequenceDogs when you're being passed a sequence of dogs? Don't the

Yes.  In particular, listDogs, tupDogs, or seqDogs.  Depending on certain
issues, I may well go so far as to write listOfDogs, tupleOfDogs, or even
sequenceOfDogs (<- especially when dealing with CORBA).

>Suppose you're writing UserDict. What do you name your function arguments
>which represent keys and values? Not too many requirements on the value
>type, are there? Is Hungarian applied only selectively?

The names would be key and value, accordingly.  Variables which hold keys
would be called keyX, keyUser, etc.  Likewise with values.

Finally, yes, Hungarian is best used only selectively.  I strongly dislike
redundant information source code.  For example:

	def PrintName( name ):
	   print "The name is %s" % name

	.
	.
	.

	for listOfNames in listOfListOfNames:
	   for name in listOfNames:
	      PrintName( name )

Note that I do NOT use Hungarian inside of PrintName(), because it would be
completely redundant.  Within the context of the function, the type of a
name would obviously have to be a string.

But outside the function, where the context could be *anything*, I use
Hungarian notation to make it patently obvious the types of data I'm dealing
with.

Some might say, "listOfListOfNames" isn't Hungarian notation.  Isn't it?
Isn't Hungarian notation just a consistent system by which you tag variable
names with the intended datatypes of the objects they hold/refer to?  If we
chose to use an abbreviation, we'd get llNames, which is decidedly closer to
what Microsoft uses in their software.

This technique is not new, nor was it "invented" at Microsoft either.
Mathematicians have often used the "Factor Label" method for solving
equations for eons.  There's a whole algebra of working with units.  For
example, if you're going X miles/hour, and you've been travelling for Y
hours, then the distance you've travelled is Z=(X*Y) miles.  Or:

	distanceZ = speedX * timeY

Why can't this be applied to computer programming too?  Given a pointer to a
pointer to an object,

	pObject = *ppObject;	/* The * operator cancels out a p */

or:

	pArgument = argv[2];
	
Oh, here's a beautiful example of 'reverse' Hungarian notation, which
someone else on this newsgroup recommended/inquired about:

	void main( int argc, char *argv[] );
			  ^	      ^
-- 
KC5TJA/6, DM13, QRP-L #1447
Samuel A. Falvo II
Oceanside, CA



More information about the Python-list mailing list