Object traversal, a minefield
quixote-users-sub@two14.net
2002-11-05
On Tue, Nov 05, 2002 at 10:24:08AM +0100, Nicola Larosa wrote:
> > Although I have read (well, skimmed, in spots) your whole treatise,
>
> Hmm... I'll take that as a compliment. ;^)
>
>
> > Markets are fire, but writing is learning.
>
> This is nice, if a bit obscure, out of context. May I quote you on this?
>
>
> >> First try. Let's go straight to an object, and then to a method.
>
> > First problem is right here: you're giving Quixote the class object,
> > not an instance of the class.
>
> That's right. What the *heck* was I thinking? :^(
>
>
> > Then you want something like this:
> >
> > def __init__(self, request):
> > view = lambda r: self._view(r)
> >
>
> I'm not sure I completely understand, or like, this hack. It's not plain
> enough for a plain guy like me. :^)
It *is* a bit tricky, but in the context it was the shortest path from
what you had (which didn't work) to something that probably would work.
It does have the virtue of cramming all of Quixote's needs into a
single class (in a setting where I would have been inclined to reach
for yet another small but separate module).
> > Unless to Quixote there *is* a difference between a class object and
> > an instance object...
>
> Wasn't that the point of your earlier comments?
Maybe. It was at this point in the learning that was writing that I
realized that the difference between these two examples didn't quite
make sense to me. Well, okay, didn't make any sense at all.
> > def Folder(request):
> > return Folder_implementation(request)
> >
> > THen you should be able to go back to using _q_exports rather than
> > _q_getname to create the proper instance object.
>
> This does not look all that different to me. I have nothing against
> _q_getname, per se. :^)
It's not all that different, but it would allow you to dispense with
_q_getname. Another approach that I didn't mention would be to always
create "empty" instances of every class that's used as an exported
namespace. In this case that would look something like
Folder = Folder_implementation(None)
Of course this has the disadvantage that you can't capture any useful
state in the class before the publisher uses it to resolve the next
path component; also, if you have many such classes the cost of
creating the mostly-unused intance might not be desirable. OTOH, I can
imagine a case where you might have many similar branches that could be
handled by the same class; then initializing a not-too-heavy class
instance might be a good balance of cost, clarity, and clean code.
Maybe something like
_q_exports = ['moe','larry','curly']
moe = Folder('/home/moe')
larry = Folder('/home/larry')
curly = Folder('/home/curly')
> > Well, this has been interesting. I'm not sure if this is yet another
> > way to structure a Quixote tree or if it's just a very different view
> > of things. Hope I've been of some help to you!
>
> *Many* thanks for your comments! They are exactly what I was looking for.
:^)))
Thanks for posing this extended question. Discussing these issues has
been enlightening for me, too!
--
The true danger is when liberty is nibbled away,
for expedients, and by parts. -- Edmund Burke