Let's start with your last question: Why support both methods and ivars,
with or without underscores?
Answer: Because different objects do different things. My own classes tend
to be method oriented, but others often use simple attributes. By having
NamedValueAccess support the different styles, I can use a string such as
'a.b.c.d' and trudge through an entire object graph without concern about
what attributes where derived or not, or encapsulated or not.
In fact, the data vs. code or encapsulated vs. naked policy of a class can
even change and "named value" reference still works.
Q: Why write a huge NamedValueAccess mix-in just to support logging?
A: I didn't. NamedValueAccess was written as a general purpose mix-in which
was inspired by NeXT/Apple's Objective-C's EOF's EOKeyValueAccess. You can
use this kind of functionality where ever it is useful for a string to
specify an attribute/method.
For example, I have a mix-in called ReplaceNamedValues (RNV) that I posted
some time ago. It's for templating using Python's well known dictionary
formatted string approach: %(foo)s. What RNV adds is that it checks all
the values, and if they don't exist in the dictionary of substitution
arguments it invokes self.valueForName(name) and puts the value in the
dictionary. e.g., the formatted string can use any method or attribute of
the object at will. And those names can traverse object relationships with
the dotted notation (and dictionaries as well).
NamedValueAccess was also useful for the Application logging.
BTW I don't think there is any overhead to having NamedValueAccess be the
base class of Object. If I remember right, it has no __init__ and does
nothing if you never ask for a named value.
Hope that's helpful,
At 02:43 PM 3/29/2001 -0800, Tavis Rudd wrote:
>I don't want to distract you from more practical issues, but I still don't
>get. Most of the WebKit code I've read so far is incredibly simple and
>intuitive, however, I don't follow the logic behind NamedValueAccess.
>Why would you write a 500 line module and a base class that is inherited by
>most of the classes in WebKit just to handle the log-writing? Couldn't
>simple eval() or exec statements could be used instead?
> From the docstring:
> >This can be useful in setups where you wish to textually refer to the
> >in a program, such as an HTML template processed in the context of an
> >object-oriented framework.
> >Keys can be matched to either methods or ivars and with or without
>Why not just use the methods as methods and the ivars as ivars
>(using exec and eval where extra magic is needed for string representations
>in templates, config-files, etc.) and be consistent in the use of leading
>I feel like I'm missing something obvious here.
>On Thursday 29 March 2001 13:05, you wrote:
> > If you look at the logging done in Application, you will see that the log
> > columns are defined like so:
> > 'ActivityLogColumns': ['request.remoteAddress',
> > 'request.method', 'request.uri', 'response.size', 'servlet.name',
> > 'request.timeStamp', 'transaction.duration', 'transaction.errorOccurred'],
> > How does 'servlet.name' get translated into something meaningful? Through
> > the power of MiscUtils.NamedValueAccess, which is one of its ancestors.
> > The actual code that makes the log is located in
> > Application.writeActivityLog().