|
![](/i/fill.gif) |
Darren New wrote:
> I agree it's a concern in CLOS that someone will read your source code
Or, to phrase it a bit differently, I'll agree that using memset() or
memcpy() to get to the entire instance opaquely *feels* qualitatively
different than the sorts of access CLOS or Python allows.
On the other hand, it seems kind of similar to the sorts of things
reflection allows.
Even in Python, I think there's two kinds of accesses:
x = myinstance._myprivatevar
vs
"iterate over all public and private variables of this instance
and do XYZ with them."
They feel qualitatively different, with the latter feeling more like
reflection and the former feeling more like bad news, even though they
both stem from precisely the same language rules.
As an example you might be able to relate to, to see what I'm talking about,
consider http://www.boost.org/doc/libs/1_38_0/libs/serialization/doc/index.html
Look at the "class gps_position" example. It has a pair of routines named
"serialize" each of which lists the exact same variables in the routine as
are in the class. With a reflection library, adding this sort of
serialization would be done by having a mix-in multi-inheritance routine,
and you wouldn't need to code that sort of body at all. Of course, there
would likely be routines like "serialize everything" and "serialize all
public members", as well as routines like "serialize everything but X and Y,
and when you load back in from the archive, invoke fix_up() on the loaded
instance to fix X and Y." So lots of uses of this sort of thing are done
from within the class, just taking advantage of the fact that you *already*
listed the names and types of the instance variables, so why do it again?
Yeah, you can use it to get to the insides of classes from outsides, but you
kind of want that for your IDE and your debugger. :-) It's a lot of power,
and IME not a whole lot of misuse.
--
Darren New, San Diego CA, USA (PST)
My fortune cookie said, "You will soon be
unable to read this, even at arm's length."
Post a reply to this message
|
![](/i/fill.gif) |