|
|
Warp wrote:
> It seems that in your quest to belittle "unsafe languages" you have taken
> some obscure definition of a term somewhere,
Not at all. I'm simply explaining why safety is important to encapsulation.
Do you think Python encapsulates data? If so, then C++ does too.
If you think Python insufficiently protects its data, then neither does any
unsafe-by-default language.
> Nowhere do I see anything related to what you wrote.
The whole "information hiding" bit, for one.
"""
Under this definition, encapsulation means that the internal representation
of an object is generally hidden from view outside of the object's definition.
"""
C++ fails this. Internal representation is in the header file. But that's
not what I'm talking about.
"""
Typically, only the object's own methods can directly inspect or manipulate
its fields.
"""
All unsafe languages fail this. (Lots of safe languages do too, with
appropriate declarations of their unsafeness.)
"""
Hiding the internals of the object protects its integrity by preventing
users from setting the internal data of the component into an invalid or
inconsistent state.
"""
Unsafe languages fail at this. Either that, or you have never ever
encountered a wild-pointer bug. The fact that you don't frequently violate
encapsulation doesn't mean that encapsulation is enforced, any more than the
fact that people don't usually screw around with the internals of Python
instances doesn't mean Python has good encapsulation in that sense.
In theory, yes, if you don't violate the language mechanisms, then C++
provides encapsulation. In practice, it doesn't, because when some value in
your object is randomly changed by a bug in some code running in other
thread, you're fairly well screwed in terms of figuring out the
encapsulation. That is, pretty much, the difference between safe languages
and unsafe languages: Safe languages *enforce* encapsulation. (And again,
most safe languages allow you to circumvent that by dropping into an unsafe
subset, but some don't.)
--
Darren New, San Diego CA, USA (PST)
The question in today's corporate environment is not
so much "what color is your parachute?" as it is
"what color is your nose?"
Post a reply to this message
|
|