Newbie Q: Data encapsulation with Ruby

Hi –

···

On Sun, 17 Aug 2003, mgarriss wrote:

dblack@superlink.net wrote:

This is what I was groping at in saying earlier that there’s no
separate category of ‘attribute’ at the language level; it’s woven
from the same cloth, so to speak, as all the code around it, but
happens to fulfill a kind of attribute-like function. Or is that too
mushy a way of looking at it?

I don’t think it’s ‘too mushy.’ One could argue that Ruby’s flexibility
in moving between the method and attribute concept is a feature and only
causes confusion when one is coming from a background where the
distinction is forced.

Just to clarify: I was questioning the mushiness of my description, not
Ruby’s behavior. I think this aspect of the design of Ruby is very
strong and clear and non-mushy :slight_smile:

David


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Or in Java. Strings are immutable, but Lists, etc., are not
(typically).

Gavin

···

On Sunday, August 17, 2003, 4:08:53 AM, Dan wrote:

Well, I think the big reason for the above problem in this case is
that Ruby Strings aren’t immutable like they are in Java. You could
have the same problem in C++:
[…]

Dan Doel djd15@po.cwru.edu wrote in message news:3F3E7334.7060704@po.cwru.edu

Well, I think the big reason for the above problem in this case is that
Ruby Strings aren’t
immutable like they are in Java. You could have the same problem in C++:

class Foo
{
string var;

public:
string & getVar();
void setVar(const string & s);
};

Foo foo;

foo.setVar(“blarg”);

string s = foo.getVar();
s[0] = ‘f’;
cout << foo.getVar(); // prints “flarg”

I agree that you could have the same problem in CD++.
Alternatively, you could declare the return type of the accessor as
‘const’, thus returning a reference, but one via which the object’s
private field cannot be modified. Yay!

You’d have
the same problem in Java with mutable objects, though.

And even in C#. I miss const.

Now I’m going to go back to scanning the horizon through binoculars,
hoping to catch a glimpse of a modern JIT-compiled language that
actually has the essential features of C++.