groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <Jason.Winneb...@windstream.com>
Subject RE: changing "with" to return self or doto
Date Wed, 06 Jul 2016 12:36:13 GMT
I actually thought it was an expected feature of "with" to be able to return a value and assign
it to a variable. I think it is bad to make such a breaking change in a 2.x version to such
a fundamental method of Groovy. I use this extensively, especially in DSLs:

@groovy.transform.Canonical class Person { String mood; int age }

def people = [ new Person("happy", 30), new Person("sad", 20) ]

def findPeople = { c -> people.findAll { it.with(c) } }

findPeople { mood == "happy" && age > 10 }

The reason why I use with instead of setDelegate + call is that with clones the closure first
while setDelegate modifies what was passed, which I think makes it not thread-safe? That's
why I use "with" there.

Jason

-----Original Message-----
From: Jochen Theodorou [mailto:blackdrag@gmx.org] 
Sent: Wednesday, July 06, 2016 8:21 AM
To: users@groovy.apache.org
Subject: changing "with" to return self or doto

We have an overlap of https://github.com/apache/groovy/pull/174 and https://issues.apache.org/jira/browse/GROOVY-3976.
That I would like to discuss.

Basically 3976 is about making "with" return the object it operates on. 
Right now we have

assert 1 == x.with {1}
assert x == x.with {it}

and after 3976 we would have:

assert x == x.with {1}
assert x == x.with {it}

The mentioned pull request goes with the same logic, but using a new method. My opinion on
this is, that we should go for a breaking change in 2.5 and change "with", instead of adding
another method on Object.

What do you guys think? Do you agree, or should we keep the current behavior, should there
be a doto method instead?

PS: just in case some people are wondering... I am trying to get some of our old pull requests
in, there are too many and keeping them open so long is an insult to contributors..

So if I do not forget about this and if there are no reactions I am going to change "with"

bye Jochen

----------------------------------------------------------------------
This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.
Mime
View raw message