Hacker News new | past | comments | ask | show | jobs | submit login

Is this to say that `attr_accessor` is too "heavy handed" when just using `attr_reader` could have sufficed?



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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: