On Jun 23, 2013, at 08:51 , Nathan Kurz <[email protected]> wrote:
> This may be the part I've missed: do you have a solution you are
> comfortable with for dealing with instance variables, particularly
> the case where the order is changed in the compiled parent library
> from one version to another? I think that is where I'm stuck without
> resorting to the techniques used by dynamic language runtimes.
The solution we came up with is that we simply don't allow direct access to
instance variables of classes from another DSO. This also applies to instance
variables of a superclass. Only indirect access through accessors is permitted.
This is of course slower than direct access but the reasons I'm comfortable
with it are:
* This use case doesn't happen very often in practice. Most of
the time a subclass is only concerned with its own instance
variables.
* Accessing instance variables of other classes directly is bad
design practice anyway. This is even true for instance variables
of a superclass from another parcel.
If you take the current Lucy code base for example, there's not a single case
where a Lucy class uses an instance variable of a Clownfish class directly.
Thinking about compiled extensions for Lucy, there are cases where it would be
a little faster to have access to instance variables of Lucy classes. The
Analyzers currently make use of direct access to Tokens, for example. So an
external Analyzer will be a bit slower but I don't think the additional 3 or 4
method calls per token make a big difference.
In the scheme we worked out, there's also a small performance penalty for
accessing instance variables within a parcel. In many cases it should be only
one additional indirection per method call (maybe two on ELF systems).
Overall, I think it's definitely worth it. I don't know of a modern programming
language that requires users to recompile their project and most dependencies
if there's a backward-compatible addition to a base class. ABI compatibility is
a feature that most users simply take for granted.
Nick