[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how expressive are they?
Sundar Narasimhan writes:
> Kragen: Nice example -- it helped me understand more about Python.
Thanks!
> But I don't see any SQL or OQL at all.. or how your "in-memory"
> objects are kept in sync w/ "other" clients. What exactly happens
> when two people run that piece of python code? How exactly does the
> second person's insert fail because of a primary key clash and how
> is it handled.
>
> And the bits you omitted are not trivial.. most of the book-keeping in
> matching relational w/ object models is in associations and keeping
> such things in sync. It's about 70-80% of the code.. it's exactly the
> sort of repetition that macros are intended to avoid.
I didn't think the part I left out trivial; I would have written it if
I thought it trivial. (And I think five to eight hours --- the time
implied by your 70-80% figure --- a rather conservative estimate of
the time it would take to produce a really useful and convenient
database mapping layer.) I don't see how syntactic abstraction helps
any more with those things than with the bits I did implement. You
don't need macros to log updates and inserts to a transaction log;
therefore, you don't need macros to do arbitrary things on updates or
inserts. You don't need macros to create classes on the fly (although
I didn't; all the instances belong to the same Python class) from a
list of strings naming the fields; therefore, you don't need macros to
create classes on the fly from a database schema you get from your
database server.
I just implemented the parts to which macros seemed relevant, like the
ability to miraculously turn ordinary assignment statements into
arbitrary code execution. I assert that you can do the rest without
macros and without per-class code duplication too --- for an example
of most of the facilities you want, I guess you could look at Zope ---
but it surprises me that the example I posted doesn't provide
sufficient evidence of this to you.
I don't know that I necessarily like reflection better than macros ---
both take a lot of effort to maintain and debug, and I'd like to see a
macro-based implementation of facilities similar to those provided by
the Python example I posted --- but I assert that you can do all the
things you have described your object managers doing in Python with
reflection: getattr, setattr, __dict__, dir, __getattr__, and
__setattr__. I offer the program in my previous post as evidence, if
not proof.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Edsger Wybe Dijkstra died in August of 2002. The world has lost a great
man. See http://advogato.org/person/raph/diary.html?start=252 and
http://www.kode-fu.com/geek/2002_08_04_archive.shtml for details.