groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Laforge <glafo...@gmail.com>
Subject Re: Re: [PROPOSAL]new operator ?=
Date Wed, 23 Nov 2016 08:12:39 GMT
At least between ||= and ?=, the latter, ?=, definitely make most sense for
Groovy.
Whether it's safe navigation with ?. or Elvis with ?:, we're still in the
same realm of nullability and Groovy Truth.

On Wed, Nov 23, 2016 at 12:57 AM, Daniel Sun <realbluesun@hotmail.com>
wrote:

> Hi Jochen,
>
>     ?= is similar with *=, +=, etc in their usage, and they are all for convenience and
readability. So if ?= does not make sense, why others does?  :-P
>
> a  = a * 2
> a *= 2
>
> a  = a ?: 2
> a ?= 2
>
> Cheers,
> Daniel.Sun
>
> --- 原始邮件 ---
>
> 发件人: "Jochen Theodorou [via Groovy]" <ml-node+[hidden email] <http:///user/SendEmail.jtp?type=node&node=5736906&i=0>>
> 已发: 2016年11月23日 上午12:47
> 收件人: "Daniel Sun" <[hidden email] <http:///user/SendEmail.jtp?type=node&node=5736906&i=1>>
> 主题: Re: [PROPOSAL]new operator ?=
>
>
>
>
> On 22.11.2016 15:25, Guillaume Laforge wrote:
> > It's a feature that's often be requested.
> > I think Ruby's got an equivalent with ||=, and it's often the reference
> > people give when exploring our Elvis operator coming from a ruby
> > background in particular.
> > I've had several opportunities where I could've used this operator.
> > It might make for a nice addition.
>
> while I agree that ||= is more like what ruby offers we have the
> problem, that for Groovy a||b always will be evaluated as boolean.
>
> In fact first we apply groovy truth to a and if that is not true, we do
> the same for b and if that is not true we return false, otherwise true.
> Which means a = a||b would not be equal to a ||= b if that is supposed
> to be the same as proposed for ?=.
>
> What would come near to that is |, which is mapped to a method call to
> "or". And then again, it has already a meaning for numbers, that does
> not fit.
>
> So for me a new operator makes more sense. But frankly...
>
> > def foo(x) {
> >   return x ?: "empty"
> > }
>
> or even
>
> > def foo(x) {
> >   x = x ?: "empty"
> >   return x
> > }
>
> vs.
>
> > def foo(x) {
> >   x ?= "empty"
> >   return x
> > }
>
> Is that really worth it? Does it really improve readability that much?
> Or maybe someone has a better example?
>
> it is different for !in and !instanceof, because of the spacing and
> because you may have them in complex expressions. But ?= is a statement
> and I would very much dislike this usage as expression.
>
> For now I am -1 on this
>
> bye Jochen
>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://groovy.329449.n5.nabble.com/PROPOSAL-new-
> operator-tp5736886p5736900.html
> To unsubscribe from [PROPOSAL]new operator ?=, click here.
> NAML
> <http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
> ------------------------------
> View this message in context: 回复: Re: [PROPOSAL]new operator ?=
> <http://groovy.329449.n5.nabble.com/Re-PROPOSAL-new-operator-tp5736906.html>
>
> Sent from the Groovy Dev mailing list archive
> <http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html> at
> Nabble.com.
>



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

Blog: http://glaforge.appspot.com/
Social: @glaforge <http://twitter.com/glaforge> / Google+
<https://plus.google.com/u/0/114130972232398734985/posts>

Mime
View raw message