[GEP]Lazy evaluation for Groovy 3

classic Classic list List threaded Threaded
14 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[GEP]Lazy evaluation for Groovy 3

Daniel.Sun
Hi all,

       Sometimes we do not want evaluate some expression eagerly(Maybe
evaluation is expensive), e.g. a table contains a field `records` whose
content is queried from DB, but we do not get the content of `records`
eagerly util we access `records`.

class SomeTable {
       def records = ( doQueryFromDB() )   // the expression in the
parentheses will be evaluated lazily
       def sum() {
             // access the methods or fields of `records`, trigger
evaluation, i.e. the query of DB
       }
       def getRecords() {
             return records // do NOT trigger evaluation
        }
}

         Lazy evaluation syntax is very simple( just supports 1) and 2) ):
1) def v = ( someExpression() )  // Lazy evaluation for variable declaration
2)  v = ( someExpression )          // Lazy evaluation for assignment
3)  println(( someExpression )) // NOT lazy evaluation

           Any thoughts?

Cheers,
Daniel.Sun



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Guillaume Laforge
Administrator
But we already have @Lazy which is a bit more explicit?

Le sam. 17 mars 2018 à 08:35, Daniel.Sun <[hidden email]> a écrit :
Hi all,

       Sometimes we do not want evaluate some expression eagerly(Maybe
evaluation is expensive), e.g. a table contains a field `records` whose
content is queried from DB, but we do not get the content of `records`
eagerly util we access `records`.

class SomeTable {
       def records = ( doQueryFromDB() )   // the expression in the
parentheses will be evaluated lazily
       def sum() {
             // access the methods or fields of `records`, trigger
evaluation, i.e. the query of DB
       }
       def getRecords() {
             return records // do NOT trigger evaluation
        }
}

         Lazy evaluation syntax is very simple( just supports 1) and 2) ):
1) def v = ( someExpression() )  // Lazy evaluation for variable declaration
2)  v = ( someExpression )          // Lazy evaluation for assignment
3)  println(( someExpression )) // NOT lazy evaluation

           Any thoughts?

Cheers,
Daniel.Sun



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Daniel.Sun
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy

Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Daniel Sun
Apache Groovy committer

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Paolo Di Tommaso
Frankly I found this confusing, it looks to me that the same concept can be implemented just using a closure. 


p

On Sat, Mar 17, 2018 at 9:08 AM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy

Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Guillaume Laforge
Administrator
I also find it confusing, in particular because it's not obvious, and there's some redundancy already with @Lazy (and Paolo has a good point as well as using closures are somewhat of a palliative as well)
Perhaps we could think of ways to further improve / expand @Lazy perhaps?
(rather than inventing something new / additional)

On Sat, Mar 17, 2018 at 12:01 PM, Paolo Di Tommaso <[hidden email]> wrote:
Frankly I found this confusing, it looks to me that the same concept can be implemented just using a closure. 


p

On Sat, Mar 17, 2018 at 9:08 AM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy




--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform

Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Cédric Champeau
-1, I also think this is confusing.

2018-03-17 13:30 GMT+01:00 Guillaume Laforge <[hidden email]>:
I also find it confusing, in particular because it's not obvious, and there's some redundancy already with @Lazy (and Paolo has a good point as well as using closures are somewhat of a palliative as well)
Perhaps we could think of ways to further improve / expand @Lazy perhaps?
(rather than inventing something new / additional)

On Sat, Mar 17, 2018 at 12:01 PM, Paolo Di Tommaso <[hidden email]> wrote:
Frankly I found this confusing, it looks to me that the same concept can be implemented just using a closure. 


p

On Sat, Mar 17, 2018 at 9:08 AM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy




--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform


Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Andrew Bayer
Agreed - I don’t think this actually provides much, if any, real value, is syntactically confusing, and feels like it could cause some problems with existing code that assumes parentheses aren’t going to result in new behavior.

A.

On Sat, Mar 17, 2018 at 8:35 AM Cédric Champeau <[hidden email]> wrote:
-1, I also think this is confusing.

2018-03-17 13:30 GMT+01:00 Guillaume Laforge <[hidden email]>:
I also find it confusing, in particular because it's not obvious, and there's some redundancy already with @Lazy (and Paolo has a good point as well as using closures are somewhat of a palliative as well)
Perhaps we could think of ways to further improve / expand @Lazy perhaps?
(rather than inventing something new / additional)

On Sat, Mar 17, 2018 at 12:01 PM, Paolo Di Tommaso <[hidden email]> wrote:
Frankly I found this confusing, it looks to me that the same concept can be implemented just using a closure. 


p

On Sat, Mar 17, 2018 at 9:08 AM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy




--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform


Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Suderman Keith-2
+1 for the concept.

-1 for using parenthesis.  As Andrew says, this introduces new behaviour for parenthesis that I think violates the principle of least surprise.

Keith

On Mar 17, 2018, at 1:54 PM, Andrew Bayer <[hidden email]> wrote:

Agreed - I don’t think this actually provides much, if any, real value, is syntactically confusing, and feels like it could cause some problems with existing code that assumes parentheses aren’t going to result in new behavior.

A.

On Sat, Mar 17, 2018 at 8:35 AM Cédric Champeau <[hidden email]> wrote:
-1, I also think this is confusing.

2018-03-17 13:30 GMT+01:00 Guillaume Laforge <[hidden email]>:
I also find it confusing, in particular because it's not obvious, and there's some redundancy already with @Lazy (and Paolo has a good point as well as using closures are somewhat of a palliative as well)
Perhaps we could think of ways to further improve / expand @Lazy perhaps?
(rather than inventing something new / additional)

On Sat, Mar 17, 2018 at 12:01 PM, Paolo Di Tommaso <[hidden email]> wrote:
Frankly I found this confusing, it looks to me that the same concept can be implemented just using a closure. 


p

On Sat, Mar 17, 2018 at 9:08 AM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy




--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform



Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

Keith Suderman
In reply to this post by Andrew Bayer
+1 for the concept.

-1 for using parenthesis.  As Andrew says, this introduces new behaviour for parenthesis that I think violates the principle of least surprise.

Keith

On Mar 17, 2018, at 1:54 PM, Andrew Bayer <[hidden email]> wrote:

Agreed - I don’t think this actually provides much, if any, real value, is syntactically confusing, and feels like it could cause some problems with existing code that assumes parentheses aren’t going to result in new behavior.

A.

On Sat, Mar 17, 2018 at 8:35 AM Cédric Champeau <[hidden email]> wrote:
-1, I also think this is confusing.

2018-03-17 13:30 GMT+01:00 Guillaume Laforge <[hidden email]>:
I also find it confusing, in particular because it's not obvious, and there's some redundancy already with @Lazy (and Paolo has a good point as well as using closures are somewhat of a palliative as well)
Perhaps we could think of ways to further improve / expand @Lazy perhaps?
(rather than inventing something new / additional)

On Sat, Mar 17, 2018 at 12:01 PM, Paolo Di Tommaso <[hidden email]> wrote:
Frankly I found this confusing, it looks to me that the same concept can be implemented just using a closure. 


p

On Sat, Mar 17, 2018 at 9:08 AM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy




--
Guillaume Laforge
Apache Groovy committer & PMC Vice-President
Developer Advocate @ Google Cloud Platform





----------------------
Keith Suderman
Research Associate
Department of Computer Science
Vassar College, Poughkeepsie NY




Reply | Threaded
Open this post in threaded view
|

Re: [GEP]Lazy evaluation for Groovy 3

paulk_asert
In reply to this post by Daniel.Sun
I think this would be best described via a proper GEP.

On Sat, Mar 17, 2018 at 6:08 PM, Daniel.Sun <[hidden email]> wrote:
Hi Guillaume,

I planed to generate proxy for lazy evaluation, so even if the reference of
object is accessed, evaluation will not be triggered either, which is
different from @Lazy

12