Derek Peirce
10/06/2019, 8:45 PMby
on constructor arguments for delegation.
class Foo(val bar by Lazy<Bar>) { ... }
would be syntactic sugar for
class Foo(barProvider: Lazy<Bar>) {
val bar by barProvider
...
}
This pattern appears over a thousand times in the codebase I'm working on, and cutting out the declared barProvider
middle-man would make switching between Bar
and Lazy<Bar>
extremely simple.Dico
10/07/2019, 11:40 AMbar
used, is it typically encapsulated or is it public?Derek Peirce
10/08/2019, 2:28 AMLazy
and Provider
dependencies so that the build graph can be constructed lazily, both of which have getValue
extension methods.
These would typically be `private val`s, with rare exceptions.elizarov
10/08/2019, 2:45 PMDerek Peirce
10/09/2019, 6:37 AMLazy
is precisely the way to add lazy evaluation of dependencies. We could put many get()
calls in the codebase, but then switching between Lazy<Bar>
and Bar
, which the framework can accept interchangeably thanks to its code generation, would also require adding or removing every get()
. Delegation makes that step simpler, but then we arrive at the pattern above, which still has some boilerplate that could very easily be avoided if one more use of by
were added.
Do you think the proposal would do more harm than good, or over-burdens the language? Or are you just considering alternatives?Dico
10/11/2019, 9:59 PMDico
10/11/2019, 10:01 PMDico
10/11/2019, 10:01 PMDico
10/11/2019, 10:03 PMprivate val bar by container.lazy<Bar>()
Derek Peirce
10/17/2019, 8:22 AM