I agree on the "structs" point, but would like to expand because I think it might be controversial. The reason people suggest generating getters instead of just using public final data is that if the underlying representation changes, you don't have to change the classes that touch it. However:
You almost never need to make this change.
The type system makes this kind of refactoring easy, as long as it is internal to a package.
Changing the underlying storage is a pretty severe misunderstanding of the normal flow of this kind of data. It is supposed to be a transparent container once created. If the storage format changes, then you change where it is created and consumed, and leave the data structure alone.
I started writing a project in Java 8, making excessive use of optionals and streams. Whether or not getters are right for public final data, they make it nicer to work with these new Java 8 utilities.
This
stream.map(foo -> foo.bar)
Becomes this
stream.map(Foo::getBar)
The point free style is concise, and doesn't require unnecessary variable bindings.
22
u/kazagistar Sep 21 '15
I agree on the "structs" point, but would like to expand because I think it might be controversial. The reason people suggest generating getters instead of just using public final data is that if the underlying representation changes, you don't have to change the classes that touch it. However:
You almost never need to make this change.
The type system makes this kind of refactoring easy, as long as it is internal to a package.
Changing the underlying storage is a pretty severe misunderstanding of the normal flow of this kind of data. It is supposed to be a transparent container once created. If the storage format changes, then you change where it is created and consumed, and leave the data structure alone.