[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ProgSoc] Deterministic destruction of objects in garbage-collected languages
Roland Turner wrote:
> I don't know enough about Python's innards to comment on it
> specifically, but can give you some of the broader view.
<broader view snipped>
Thanks for that description, particularly the Java bits. Python used to
be reference counted, but now also has a GC to take care of reference
cycles. A bit yucky.
> try {
> Connection c = pool.takeConnection();
> doMyStuff(c);
> } finally {
> c.release();
> }
Python does indeed support and encourage this idiom, but it's not
particularly nice (in Python terms):
try:
c = pool.take_connection()
do_stuff(c)
finally:
c.release()
It's quite a complicated block structure for such a common idiom, so the
"with" statement in Python 2.5 was introduced which (as I understand, I
haven't actually used it yet) would turn the above into something like this:
with c = pool.autoreleased_connection():
do_stuff(c)
In my specific case though I really only wanted the connection to be
around for the lifetime of the function call, and this is a case where a
RAII-like approach would have been lovely:
Connection c = pool.take_connection();
do_stuff(c);
I guess I want static scoping sometimes. ;)
- Nicholas
-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.