how to count lines in a file ?

Bengt Richter bokr at oz.net
Wed Jul 31 14:27:26 EDT 2002


On 29 Jul 2002 00:25:59 -0400, list-python at ccraig.org (Christopher A. Craig) wrote:

>bokr at oz.net (Bengt Richter) writes:
>
>> I like this, but I think I would rather see timely finalization
>> subsumed under a general event-handling mechanism for objects. Thus
>> ref count going to zero would be a standard event that you could
>> write a handler for.
>
>You're still assuming that the standard deals with such a thing as a
>reference count.  One of the points of this whole thread (to my mind)
Yes and no. You have a point. I was assuming there is/was/will be a platform
with reference counting, and that such a platform (whose platform-specific events
would be referenced in sys.events or such) would have a standard event ID for
reference count of an object going to zero.

So yes, reference count going to zero is too platform specific to be
in the same league as an abstract finalization event which might be something
to add to the language (I assume this is the gist of your point), and no,
that doesn't mean I expect all systems to have reference counts for all objects
and for that to be part of "the [language] standard".

For a platform without (or with specialized limited) reference counting, we would
have to find or create another event which could underlie the abstract finalization
event. Alex's local(...) construct could provide a leaving-scope event that could
serve as the equivalent for object references created within its scope.

>has been that, though it is well known that CPython uses reference
>counts for garbage collection (and people mistakenly depend on this),
>the actual language standard does not require it.  This means that any
>code that depends on reference counts, in any way, is not only not
I think "any way" is a bit broad, but I take it you mean source code
that specifically refers to reference counting one way or another.
I think you would agree that a low level dependency on platform specifics
is necessarily part of constructing a platform-independent level of abstractions.
If there were a general purpose mechanism for event handling (and triggering),
I would expect it to handle both platform-specific and platform-independent
events. Timely finalization is the abstract concept, and reference counting
going to zero is a platform-specific event that could be used to implement it.
My example wan't the best, since it appeared to suggest general user-level use
of a ref count event per se (which I assume was what mainly you reacted to).

Of course, events encompass more than synchronous events within a single thread,
so there is more to think about (and we are already 'way OT for this NG thread ;-)

>portable to Jython (or any other non-CPython compiler), it's not
>necessarily compatible with all future versions of CPython.
>
I think you are right that the language definition should not depend on reference
counting, but I think general purpose event mechanisms may and should be able to
name and deal with platform specific events, so that they can be used to build
a platform independent layer of events and features.

>So if Guido decides today that reference counts were a dumb idea and
>he would be better off with a simple mark-and-sweep GC, he can
>implement one and not lose too much sleep over the weeping and
>gnashing of teeth from those that depended on the behavior of the
>current compiler. <.8 wink>
>
I'm sure he would give due consideration to all factors ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list