Re:“A closure is a poor man’s object; an object is a poor ma...
by cagmz on Monday May 01, 2017 @10:31AM
(#14237685)
Is this to say that `attr_accessor` is too "heavy handed" when just using `attr_reader` could have sufficed?
[ Parent
| on HN ]
Re:“A closure is a poor man’s object; an object is a poor ma...
by eropple on Monday May 01, 2017 @10:46AM
(#14237857)
It's not about heavy-handedness, it's that `attr_accessor` breaks encapsulation of private state and code very rarely takes into account what actually updating that member variable does.
It's used mostly because novice Rubyists are told that that's how you make a variable accessible, not that that's how you make it read-writable. In C#, on the other hand, when you create a property that's the moral equivalent, there's a lot more of a focus on creating getter-only properties that reveal state but don't let you munge it.
Ruby is also pretty bad about using #freeze and #taint, but the latter is a lost cause.