From: bjsp123@... (Benjamin Peterson) Date: 2003-08-18T18:20:32+09:00 Subject: Re: Newbie Q: Data encapsulation with Ruby Dan Doel 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++.