Coding standard: Prefixing variables to indicate datatype

andy andy at eastonwest.co.uk
Fri Jan 17 18:27:43 EST 2003


I tried a bit of Novell NDS client programming, a while back, with Delphi.  
Their Delphi API is RIDDLED with 'elongated' hungarian prefixes; instead of 
just c for char, s for string, i for integer and so on, they have developed a 
'system' of long 3-5 character prefixes for each data type.  Sometimes, you 
need to convert from, say, a Delphi Object string, to a zero-delimited 
string, and then pass the *pointer* to this to the API, like this:

	strUserName: string;

	stzUserName: array [128] of char;

	lpstzUserName: pointer to char;

Ugly as sin, and it makes justabout any half-line equation three times as 
long, and utterly indistinguishable.

With Python, I generally only use any form of hint if I'm converting from one 
data type to another, and it's not a 'throw-away' assignment.  I'd do this 
sort of thing (dubious contrived example):

	x=getanum() # x now contains a number
	xstr=str(x)
	# do stuff with xstr

As most people have said, it's not normally necessary, and just adds to the 
complication (and thus detracts from the readability) of your code.  I feel 
that using a suffix is less likely to obsure the purpose of a variable than a 
prefix, but even then, if the code begins to get too unwieldy, I'd hack the 
suffix off to get control back!

regards, 
-andyj





More information about the Python-list mailing list