Design tips requested for OOP forum system (using pickle)
Andy Todd
andy47 at halfcooked.com
Fri Nov 30 00:12:03 EST 2001
"Graham Ashton" <graz at mindless.com> wrote in <56zN7.139$Jm.5630 at stones>:
>In article <eb8b2b6e.0111291359.64a1ee62 at posting.google.com>, "Simon
>Willison" <cs1spw at bath.ac.uk> wrote:
>
>> I'm something of a Python newbie but I'm keen to learn so I've decided
>> to throw myself in at the deep end.
>
>Good plan. The fastest way to learn, I reckon.
>
>> Anyway - I've decided to code a flat threaded web forum system ... using
>> pickled objects in flat files to store the data (rather than using a
>> database or a delimited flat file format of some sort).
>
>Here's an idea to think about; see if you can work out how to design a
>fairly generic interface to your storage. Implement it first with pickle
>(cPickle is much faster by the way) and then see if you can fiddle around
>with it a bit so that it supports different storage systems (e.g. anydbm),
>selectable at run time. Design patterns will be your friend here, and are
>very interesting ways of taking your OOD knowledge beyond the standard
>inheritance and delegation techniques.
If your interface is generic enough it is but a small step from pickle to
database type storage (either an object database like ZODB or a relational
database).
>
>Top pickle tip (cPickle isn't available everywhere):
>
> try:
> import cPickle
> pickle = cPickle
> except ImportError:
> import pickle
Let me save you a whole line of code here;
try:
import cPickle as pickle
except ImportError:
import pickle
>
[snip some great tips and hints]
>
For what it is worth, you will probably end up needing a fast efficient
database server to store your data in. I know you are building this project
as a learning exercise but consider porting the data storage of your
(nearly) finished version to something like MySQL or PostgreSQL as an
exercise in OO <-> RDBMS mapping. That one can twist even the finest minds
into knots ;-)
Regards,
Andy
--
Content free posts a speciality
More information about the Python-list
mailing list