On 09.11.2016 14:56, Winnebeck, Jason wrote:
My concern about "withThis" is that it implies that "this" is the parameter of
the closure and not the return. We have for example withReader, withWriter, withOutputStream, etc.
Those all imply that the parameter is the reader, the writer, the output stream. So in my mind,
withThis tells me nothing at all about the fact that the original object is returned. withThis
would not be consistent with the rest of Groovy.
I agree with this one.
.with(returnThis:true) not only has runtime overhead, but keep in mind we are
comparing this to the current state today, which is .with { return this }, or
.with { this } depending on your style.
here I have to correct a bit though. Just want to avoid we start
discussing the wrong thing... And I just noticed Paul made the very same
mistake in the original post already. Well, maybe not too late yet
we are talking about
foo.with {
return foo
}
or
foo.with {
return it
}
not about something returning "this" at any point. "return this" would
return neither the open block, nor foo, it would be the enclosing class
instance. No delegate has influence about any explicit this ever.
Ah, and I did just see Jason noticed it in a later mail... well, maybe
saying it two times is better ;)
Anyway, that´s why I think withThis and with(returnThis:true) are not
good variants.
Also it should be noted that we already have an alias for "with", which
is "identity". I would not want to have yet another one.
Frankly... I think we should change what it returns. It is unlikely
somebody did depend on with returning null.
bye Jochen