Re:Why I Don't Like Golang (2016)
by sdegutis on Wednesday June 12, 2019 @06:49PM
(#20170159)
I liked a similar aspect of Ruby: attributes and 0-args methods had the same syntax, so you could easily refactor a static field into a method that returns a dynamically calculated value. Overall I don't like that feature, but that was a very handy aspect of it.
[ Parent
| on HN ]
Re:Why I Don't Like Golang (2016)
by ben-schaaf on Wednesday June 12, 2019 @07:03PM
(#20170254)
Ruby actually went one step beyond: there are no attributes. `attr_reader` just generates a 0-arg method, while `attr_writer` just generates a 1 argument `name=` method.
TBF that's pretty directly inherited from the Smalltalk ancestry: just like Smalltalk, Ruby simply doesn't have public (data) fields. Although it does provide shortcuts for automatically generating accessors which I don't think Smalltalk did / does.
Funnily enough, Self opted for the opposite tack of not having private data fields (although it does have readonly and read/write slots), but you can trivially swap "data" slots and "method" slots: http://handbook.selflanguage.org/2017.1/langref.html#constru...
> Although it does provide shortcuts for automatically generating accessors which I don't think Smalltalk did / does.
Most Smalltalk browsers do actually offer this capability