3 ms·
Agreed, the declaration syntax is awful and the generated methods aren’t idiomatic. That saidC I don’t even understand the point of generating getters in this
by doctor_eval 7y ago
Agreed, the declaration syntax is awful and the generated methods aren’t idiomatic.
That saidC I don’t even understand the point of generating getters in this case. The fields could just be declared public final. Java’s obsession with wrapping fields in methods has never made sense to me.
- erik_seaberg 7y agoScala lets you quietly replace a field with an accessor method, but Java does not. You'd have to change all consumer code to add laziness or test mocking/spying.
- doctor_eval 7y agoin my experience accessor methods are a particularly nasty kind of YAGNI. I'm not saying you never need to override a field to make it lazy, for example, but the cost of getters and setters has never, in my practical experience, outweighed the cost.
- erik_seaberg 7y agoIf they're generated and inlined away, what's the remaining cost?
- doctor_eval 7y agoThe cost is in typing effort, fluency, legibility and complexity. There is no Good reason to prefix every field access with get, and end it with (). It’s five more keys to type and makes the code more verbose. thing.getId() is longer and less readable than “thing.id”. Why does the compiler have to spend time inlining the call? Can you guarantee that it does? IMO the question shouldn’t be “what is the cost of this complexity?” The question should be, “what is the benefit?”. And in 20+ years of java dev, I just don’t see any benefit in accessor methods at all. We never wire up our components with JavaBeans introspection... so why do we keep this nonsense going?