From: Rich Kilmer Date: 2001-10-24T16:20:28+09:00 Subject: [ruby-talk:23146] Re: Bruce Eckel's opinion of Ruby > -----Original Message----- > From: Emiliano [mailto:emile@iris-advies.com] > Sent: Wednesday, October 24, 2001 2:04 AM > To: ruby-talk ML > Subject: [ruby-talk:23142] Re: Bruce Eckel's opinion of Ruby > > > Alan Chen wrote: > > > All large scale development languages allow access to private data, > > its a matter of how much pain you want to put the developer through if > > they elect to access a non-public interface. FWIW, I suspect that it > > would be easy to write a module to disable the send and method > > functions in a class. (or provide a warning if you'd prefer) > > But it still wouldn't be the default behaviour. Having class-private > data available publicly by default isn't correct in my book. You have > to choose what to make part of your public interface. IMO, of course. > > Emile > > In the following I am not trying to be anti-Python...just trying to set the record straight... Regarding "private" class variables. So...in Python you can use this: obj.__dict__['attrName']=value ...to get direct access to (get/set) the values of every attribute on an object. In Ruby every object attribute is private and can only be accessed through a method...period. Exposing the __dict__ "bag" on an object exposes the entire state of that object for public consumption. Ruby and Python can both be easily "subverted" by default (Ruby through "instance_eval" and "send"), but in Ruby you can explicitly block your class/object from being effected by overriding those methods. The same is NOT true for Python. It provides "privacy" through obfuscation (name mangling) but its still easy to get around (because everything is still held in the __dict__). From the Python tutorial: "Name mangling is intended to give classes an easy way to define ``private'' instance variables and methods, without having to worry about instance variables defined by derived classes, or mucking with instance variables by code outside the class. Note that the mangling rules are designed mostly to avoid accidents; it still is possible for a determined soul to access or modify a variable that is considered private. This can even be useful, e.g. for the debugger, and that's one reason why this loophole is not closed. " OK...that's the end of my Python rant :-) -Rich