Giovanni Bajo schrieb:

Just one personale note: right now, I usually do:

from qt import *

because I find it useless to write "qt.QApplication" instead of
"QApplication" since the leading uppercase "Q" is already a kind of
namespace, which is imposed by qt itself. If (by absurd) the class was named
"Application", I would probably use "qt.Application".

The same applies for QT4: I don't think I'm being helped by writing
"QtGui.QApplication" as I'm not going to write a class with a leading
uppercase Q in any case (it'd be confusing). So, as long as I am able to
write:

from PyQt4.QtGui import *

and subsequently use "QApplication", I'll be happy.


Just another personal note: :-)

Using from ... import * in normal code is (and was) always a bad idea. I have avoided it whenever possible. You pollute your local namespace with all names from the imported modules and name clashes are are likely to occur. Are you always absolutely sure, that a name defined in any of the qt modules is never defined in any other module that you import?

There are situations, where such an import contruct makes sense. When you have a wrapper module for example, that wraps an extensions module, it is ok to load all definitions from the extension module into the namespace of the wrapper module. In normal applications, it should be avoided whenever possible.

Another point is that keeping the source code readable is much more important than saving a few character typings. Reading qtsql.QDateTable and qttable.QCheckTableItem is as clear as possible, because I can see, where both names belong to. Reading QDataTable and QCheckTableItem, I always have to worry where the names come from (I would guess qttable, because the word 'Table' occurs in both names).

When you have to maintain a large amount of code for a long time, readability is one of the most important things.

Believe me, I know what I'm talking about:
My oldest application contains 35000 lines of code and is running over 6 years on 120 machines, my largest application contains over 40000 lines of code and is running over 4 years on 60 machines. Try to maintain such applications if you make heavy use of import *. Your best friends will become 'grep' and 'find', always searching for the one module where this damned function 'foo' is defined.


Ulli


_______________________________________________ PyKDE mailing list [email protected] http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to