Re: What databases have taught me

Robert Martin <unclebob_at_objectmentor.com> wrote:
> I've looked over the thread you referenced above. You asked whether > 'this' and 'self' were kind of like fields in OO languages. I refuted > this by saying that, at least in C++, 'this' is not like a field, > because it's value depends on the method being called. If the method > of a base class is called then 'this' will point to the base class and > not to the class of the object itself. (This only matters in cases of > multiple inheritance). You then asked me for the definition of > "field", and I did not answer that (yet).

I suppose they say "fools rush in...", so I'll prove that about myself
now. :) (By which I mean, PMFJI.)

I don't find it particularly compelling to distinguish this/self from
instance fields in that way, especially since the distinction appeals
primarily to implementation rather than the actual meaning of what's
going on. I could very easily implement C++ in such a way that 'this'
remains constant regardless of its static type in terms of the
inheritance hierarchy. The only thing I'd lose is a bit of performance
in metghod dispatch. I would rather tend to make the distinction by
arguing that "this" (or "self") is a more fundamental concept than
instance variables. That is, the implicit knowledge by the code in an
instance method of the object that is being operated on comes logically
prior to the knowledge of what the instance variables are.

This, incidentally, is why I don't much like some of the formal models
for OO programming in the research sphere. They get this concept wrong,
and model the availability of the object to itself (this) separately
from the availability of its state. This mistake seems to be
recognizable by the occurrence of the term "open recursion" in the
description of the formal model. The result is a kind of disconnect
that makes the model difficult to apply in reality.

> So, in OO, a field is more often known as an instance variable.

Wouldn't it be quite the opposite? I've never heard a Smalltalker go on
about instance variables. Rather, that phrase seems to be restricted to
old C programmers working in C++ or Java.