Hungarian notation (was RE: variable naming...)

Ben Hutchings ben.hutchings at roundpoint.com
Fri May 4 02:11:00 CEST 2001


John Schmitt <jschmitt at vmlabs.com> writes:
<snip>
> I do not see any value at all in naming
> it this way:
> 
> typedef struct
> {
> 	int ix;
> 	int iy;
> } stPOINT;
>
> void vstPOINTSet( pstPOINT* pstpoint, int ix, int iy )
> {
> 	pstpoint.x=ix;
> 	pstpoint.y=iy;
> }

That's Hungarian naming as practised by Windows hackers, which is not
the same as what Simonyi actually proposed.

<snip>
> Now, if you write a program that uses the above-mentioned struct in a bunch
> of places, what will you do when it's time to refactor?  Supposing that
> someone decides that we in fact need floats rather than ints to represent
> points?  Search and replace?  Hand editing?  That's a good waste of my time.

No, instead you would say:

    typedef int Coord;
    typedef struct { Coord x; Coord y; } Point;

or even:

    typedef int XCoord;
    typedef int YCoord;
    typedef struct { XCoord x; YCoord y; } Point;

(prefixes for type names aren't part of Hungarian naming).  Then you
would use the new type names to declare coordinate variables, and give
all the variable names prefixes of 'x' and 'y'.  When you want to
change them to be floats, you change the typedefs.  That's how
Hungarian naming is supposed to work.

<snip>
> In the specific case of Python, since types are not statically declared, it
> makes even less sense to embed the type inside the variable name.
<snip>

However, most names are only meant to be bound to objects that
implement an interface such as 'container' or 'file-like', and that
interface is like an abstract type that could be encoded in the name.

-- 
Any opinions expressed are my own and not necessarily those of Roundpoint.



More information about the Python-list mailing list