Design tips requested for OOP forum system (using pickle)

Simon Willison cs1spw at bath.ac.uk
Thu Nov 29 16:59:34 EST 2001


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. My objective is to "learn" python
(or at least get to a stage where I feel confident writing larger
applications in it) and at the same time get the hang of object
orientated design for a "real" software system (I've been slowly
learning OOP over the last few months and I'm itching to try it out).

Anyway - I've decided to code a flat threaded web forum system
(similar to UBB or vBulletin) in Python using pickled objects in flat
files to store the data (rather than using a database or a delimited
flat file format of some sort). I'm doing this primarily as a learning
exercise, so performance and scalability aren't that important.

I'm having trouble figuring out the best way to design the classes for
the forum. Here's what I have so far:

User - an object representing a single forum user account
Forum - an object representing a forum (e.g "General Chat" or "Site
Suggestions")
Thread - an object representing a thread
Post - an object representing an actual post

In addition I'm keen on having Moderator and Admin classes which
extend User and are used for forum accounts with extra ablities.

Post objects will be held in an array within a Thread object
(representing the thread the posts were posted on). Thread objects
will be held in an array within a Forum object.

One thing I haven't quite figured out yet is how to relate posts to
the user object for the user that posted that post. Should I look at
storing some kind of user ID and then searching through my user
objects for an object with that ID stored within it every time I
display a post? That sounds horribly inefficient - performance is not
a major concern for this software as it's intended for personal small
scale use but I don't want to write something that's virtually
unusable due to performance problems...

I'm also not entirely sure how to do things like ordering posts witin
threads by date - should I ensure they are in order within the array
or sort the objects by their date property (which I assume will
require me to write my own ordering algorithm, presumably not hard but
something I've never had to do before).

My final problem (I think) is how to split pickled data up. Should I
have an OverallForum object which contains ALL the objects (and data)
within it and pickle/unpickle the whole thing for every page view
(sounds inefficient) or pickle individual forums in their own files.
If I store individual forums in their own file how will I maintain
references to User objects possibly pickled elsewhere?

Any tips / pointers / warnings that I'm going about this project
completely the wrong way would be more than welcome :)

Thanks,

Simon



More information about the Python-list mailing list