On Sat, Sep 14, 2013 at 12:29 PM,  <[email protected]> wrote:
> Replace *_Dec_RefCount with DECREF

> Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
> Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/6f48dc35
> Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/6f48dc35
> Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/6f48dc35

This change reminds me of Python and how you call `str(obj)` instead of
invoking `obj.__to_string__()`.  It's an elegant system, and maybe it might be
nice to borrow some other aspects.

    $ python3
    Python 3.3.0 (default, Oct  3 2012, 17:10:41)
    [GCC 4.2.1 Compatible Apple Clang 4.0
((tags/Apple/clang-421.0.60))] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from pprint import pprint
    >>> obj = object()
    >>> pprint(dir(obj))
    ['__class__',
     '__delattr__',
     '__dir__',
     '__doc__',
     '__eq__',
     '__format__',
     '__ge__',
     '__getattribute__',
     '__gt__',
     '__hash__',
     '__init__',
     '__le__',
     '__lt__',
     '__ne__',
     '__new__',
     '__reduce__',
     '__reduce_ex__',
     '__repr__',
     '__setattr__',
     '__sizeof__',
     '__str__',
     '__subclasshook__']
    >>>

For what it's worth, DECREF and INCREF perform NULL-checks, while invoking the
methods directly do not.  In all the cases where Dec_RefCount() or
Inc_RefCount() had been invoked directly, the objects were guaranteed to be
non-NULL.  However, the cost of the extra NULL check is surely negligible and
so there's no harm in standardizing on DECREF and INCREF.

Something to consider is that there's little value in making the Clownfish
core runtime classes extensible.  Lucy subclasses Hash, but it's a nasty hack
and we could have just written our own hash table implementation from scratch
anyway.

What do you think of making all the core runtime classes final except for Obj?
There are advantages to limiting ourselves to a single carefully designed
extension point.

Marvin Humphrey

Reply via email to