Need some help managing project and making it a little simple (pretty messed up code)

dieter dieter at handshake.de
Thu Aug 17 02:08:18 EDT 2017


Kryptxy via Python-list <python-list at python.org> writes:
> ...
> I am new to python. While learning python, I began a side project. Its a command-line search program.
> ...
> But, I am unable to understand how I should begin structuring the project (updating code according to OOP). If someone could have a look? Could really use some suggestions/ideas.

Manageing larger projects is in general helped by some kind of modularization:
you split the whole implementation into different parts which have
high internal and low external interaction. While the total
complexity increases, you have often a chance to concentrate
on a part only and this part is far less complex the the whole.


OOP is just one kind of modularization. Not all problems can
make high use of OOP modularization.


For OOP friendly problems, you can easily identify objects. They have
state and functions operating on this state (those functions are called
"method"s). The state is mostly relevant only for the object internally
and less (if at all) for the external world.


In your case, the search service itself might be an object. And the queries
might be objects. To gain something, you must have interesting
operations on those objects - operations that manipulate a mostly irrelevant
(but fairly complex) internal state.

> Also, can someone point me to some (small) project where something similar is being implemented?

You might have a look at "Products.AdvancedQuery" (--> "PyPI").
Download its source; you will find a documentation in the
folder "Products/AdvancedQuery/doc/". It models
queries as objects and the relevant operations are query constructors.

You (likely) will not be able to "run" it. It depends on
a search service called "ZCatalog" (part of the web application framework
"Zope"). This search service, too, is implemented by an object.
To use it, you would need "Zope". But you can download the source
(--> "PyPI"; its name is "Products.ZCatalog") and look
at the interface description in "Products.ZCatalog.interfaces.py"
to learn about the "ZCatalog" methods. This file also contains
a good documentation (via so called "docstring"s).


Interfaces are a general way to document the relevant parts
of objects/classes for "external use". They are heavily used by "Zope".






More information about the Python-list mailing list