3 ms·
I have some issues with this feature. 1. I don't really like this immutable approach, I want setters too. 2. I don't need those autogenerated equals/etc impl
by vbezhenar 7y ago
I have some issues with this feature.
1. I don't really like this immutable approach, I want setters too.
2. I don't need those autogenerated equals/etc implementations, it's just code bloat. May be it's OK to introduce some syntax to automatically generate them like `String toString() default;` but it should not be implicit.
3. It uses non-standard getter syntax. Java developers used `getProp()` forever, now it's `prop()`. Shall we rewrite old classes or tools? Shall we live with two different styles in one codebase? Both approaches are bad.
This feature looks very out of place in Java. I hope that it'll be removed in the next release and replaced with something more compatible with old code. I waited forever to get short property syntax in Java and got unusuable feature in the end. I don't want to migrate to Kotlin just because of properties.
- _bxg1 7y ago> I don't really like this immutable approach, I want setters too. > I don't need those autogenerated equals/etc implementations, it's just code bloat. May be it's OK to introduce some syntax to automatically generate them like `String toString() default;` but it should not be implicit. It sounds like you just want... regular classes? I don't understand your position here. Immutable data structures have many uses and are quite popular. If that's not what you want, why use these at all? > Java developers used `getProp()` forever, now it's `prop()`. Shall we rewrite old classes or tools? Shall we live with two different styles in one codebase? C# is the same way. The getProp() convention isn't as strong because it's had computed properties for longer, but one doesn't have to preclude the other.
- Rebelgecko 7y ago>It sounds like you just want... regular classes? I don't understand your position here. Immutable data structures have many uses and are quite popular. If that's not what you want, why use these at all? Records provide a lot of syntactic sugar that classes don't (which is the whole reason to use them— there's nothing stopping you from creating a regular class with all final fields). edit: I'm assuming that the "finality" of fields in records is identical to the shallow finality of a final field in an object
- dmitriid 7y ago> It sounds like you just want... regular classes I wish Java provided syntax sugar similar to C#'s with {get; set;} and quick initialization with new C { field1 = X, field2 = Y, ... } Java is unnecessarily verbose in this regard. Records bring syntactic sugar to records only. And you're stuck with pages upon pages of unnecessary boilerplate code for classes.
- fgonzag 7y agoSo you don't want records, you want something else. The rest of us who've use kotlin's data classes or similiar features in other languages really like the first two points (the third point I don't mind but I don't like it either).
- krzyk 7y ago> 3. It uses non-standard getter syntax. Java developers used `getProp()` forever, now it's `prop()`. Shall we rewrite old classes or tools? Shall we live with two different styles in one codebase? Both approaches are bad. This was used in the olden days, nowadays developers prefer not to use pointless words in method names. I really like those, and it also strengthen the fact that records are not java beans. If you want those you should write a regular class.
- mumblemumble 7y agoI'm trying to decide how I feel about the naming convention. On the one hand, I don't want there to be two conventions for no reason. On the other hand, I think I see a reason: `getProp()` is a method that might do _anything_, up to and including making some I/O call that might fail. With a record's `prop()` call, though, I can expect that it's just getting a value. And I sure wouldn't mind having a convention that `valueName()` is a lightweight getter, whereas the 'get' in `getValueName()` is a warning to be on guard for side effects. To the first two, it sounds like maybe you just don't want what it's offering. The autogenerated equals, etc can only work sensibly if instances are immutable. And if instances are immutable, enforcing a value-level comparison so that you can have predictable, standardized semantics around one of the pricklier bits of how a datatype is defined makes a fair bit of sense.
- philjohn 7y agoWhy do you want mutable objects?
- vbezhenar 7y agoBecause they are more convenient and performant. Immutable objects have their place, of course.