3 ms·
Good points. It'd be great if the kotlin compiler could produce builders or "withers" automatically.
by thu2111 7y ago
Good points. It'd be great if the kotlin compiler could produce builders or "withers" automatically.
- lmm 7y agoWould you really want them? If you write code in that style then you're giving up a lot of the advantages of Kotlin. IMO there's a contradiction at the heart of Kotlin's positioning. As the quote goes, a language that doesn't affect the way you think about programming, is not worth knowing. If programming Kotlin is just like programming Java, why not just keep programming Java? If you want to switch to Kotlin because it's going to unlock a better way of programming, then that's going to have to mean changing how you program. It may work as a trick to get users on board at the start, but ultimately the language will have to find its own idioms and patterns, or else go the way of CoffeeScript.
- thu2111 7y agoI'm talking about what it compiles down to. Kotlin routinely generates bytecode that uses Java idioms either for its own ABI or in addition to it. So yeah, if some builder classes were produced behind the scenes for an immutable data class, why not, that'd be cool. You could always disable that feature with a flag if for some reason the bytecode size was an issue.