[Tutor] Creating and storing objects from a GUI...
Thu, 21 Feb 2002 16:44:52 +0100
On 0, Israel Evans <email@example.com> wrote:
> I'm in the midst of designing a program that will be creating new instances
> of a number of classes and then storing that information somehow. I'm in a
> little bit of a quandary as to how I should go about this. There are so
> many options! I'm still rather inexperienced at this sort of thing so I'm
> having a tough time knowing the "right" way to do a number of things. I
> know that "right" is rather subjective based on one's needs, but if anyone
> has any "more right than wrong" sorts of answers, I would be most
> I'd like to display the information in a variety of ways, and I'd like to be
> able to do searches, and queries in a variety of ways, so I'm thinking that
> XML saved in a Database of some sorts might be nice, but would it just be
> simpler and take up less space to save things off in plain text format, or
> even pickle the objects I create?
It depends :) How is your program used, how many records, that sort of thing.
There is a rule of extreme programming that I like: do the simplest thing
that can possibly work. If after a while it turns out you need something
heavier, you can code and then and move the data over. You might have to
make the system more complicated later, but half the time it turns out it's
not necessary after all, and much of the rest of the time your program has
been completely redesigned by that later time anyway.
So for one thing, XML in a database sounds like too much to me. Why the XML?
Most things should fit into a database table without XML stuff, and would be
far easier to search.
Pickle is probably the simplest thing that works, it's very easy to use.
It has a dictionary style interface, so you can only search very fast on the
key you use to index the pickle, but if the number of objects isn't that
large (say, a few thousand) then you can just loop through them.
A problem with pickle is concurrency. If your program has multiple threads,
or multiple copies of the program will be using the same pickle file at the
same time, there will be problems. If there are any issues like this, pickle
is out, and databases immediately look good. I'm not certain it's a problem,
but I would be very surprised if it wasn't.
> What are the benefits of using the ZODB over a relational DB like
> PostgreSQL, or MySQL?
I don't know. I believe it organizes the data differently; your data can
probably be represented by means of tables, then you want a relational DB.
> This program is expected to retain records of transactions and appointments
> for quite a long time and the sheer volume of them may get up there in size
> over time. If my little program doesn't cut it in the end, I'd still like
> to be able to easily migrate the date elsewhere.
Whatever you choose, it shouldn't be hard to just read out the data and put
it into the new solution whenever you change it.
If there are no concurrency problems, I'd just use pickle for now. Think
carefully of which functionality you need, write functions for that, that
use pickle internally, so that if you change to a database, only those
functions need changing.
Just my thoughts - I don't have much experience in this area, so these are
pretty generic comments.