Do I always have to write "self." ?

Andrew Dalke dalke at acm.org
Mon May 1 02:13:04 EDT 2000


Steve Crane wrote:
>Hungarian Notation was introduced by Charles Simonyi (who happened to
>work for Microsoft).
[...]
>While it may seem to make code harder to read it is in fact very useful
>when working on large projects involving may programmers.  However if
>you're writing a program yourself and don't think that anyone else will
>ever have to read the code you can probably steer clear of Hungarian
>Notation in either form.


I've always had problems mixing Hungarian Notation with the ideas
of generic programming.  Suppose you have:

def max(x, y):
  if x < y:
    return y
  return x

or, in C++ (assuming I remember how to do C++ after years of Python :)

template <class T>
T& max(T& x, T& y) {
  if (x<y) {
    return y;
  }
  return x;
}

What's the proper prefix notation for "x" and "y"?  It's something
like can_be_compared_x and can_be_compared_y, which is a description
of what you can do with them, not what they are.

(A more canonical example, from Alexandar Stepanov of C++'s STL
fame, is greatest common divisor.  The same algorithm can be used
for integers and polynomials.)

I do like generic programming.  I've managed to have some very nice,
clean systems which don't care what the data types are, so long as
they met the right protocols.

                    Andrew Dalke
                    dalke at acm.org






More information about the Python-list mailing list