You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Pawan Verma <pa...@hotwaxsystems.com> on 2019/05/15 12:29:15 UTC
Code Improvement for Groovy
Hello Devs,
As we all know, Groovy is a powerful language with great built-in
functions. Groovy Truth[1] is one of them, which is not used properly in
our code base. We have used UtilValidate Class to validate arguments for
Empty or NotEmpty, which can easily be done in groovy with built-in
functionality.
Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
Groovy Built-in Code: if (locations) { ... }
IMO, We should use this Groovy Truth feature instead of UtilValidate Class.
Please let me know your thoughts on this. Thanks!
[1] - http://groovy-lang.org/semantics.html#Groovy-Truth
--
Kind Regards
Pawan Verma
Technical Consultant
*HotWax Systems*
Re: Code Improvement for Groovy
Posted by Rishi Solanki <ri...@gmail.com>.
+1
Best Regards,
--
*Rishi Solanki* | Sr Manager, Enterprise Software Development
HotWax Systems <http://www.hotwaxsystems.com/>
Linkedin: *Rishi Solanki*
<https://www.linkedin.com/in/rishi-solanki-62271b7/>
Direct: +91-9893287847
On Wed, May 15, 2019 at 8:33 PM Jacques Le Roux <
jacques.le.roux@les7arts.com> wrote:
> Hi Pawan,
>
> Sure, we use that from start a lot. But some don't it seems. A Jira fits
> with me
>
> Le 15/05/2019 à 14:29, Pawan Verma a écrit :
> > Hello Devs,
> >
> > As we all know, Groovy is a powerful language with great built-in
> > functions. Groovy Truth[1] is one of them, which is not used properly in
> > our code base. We have used UtilValidate Class to validate arguments for
> > Empty or NotEmpty, which can easily be done in groovy with built-in
> > functionality.
> >
> > Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
> >
> > Groovy Built-in Code: if (locations) { ... }
> >
> > IMO, We should use this Groovy Truth feature instead of UtilValidate
> Class.
> > Please let me know your thoughts on this. Thanks!
> > [1] - http://groovy-lang.org/semantics.html#Groovy-Truth
> >
> > --
> > Kind Regards
> > Pawan Verma
> > Technical Consultant
> > *HotWax Systems*
> >
>
Re: Code Improvement for Groovy
Posted by Jacques Le Roux <ja...@les7arts.com>.
Hi Pawan,
Sure, we use that from start a lot. But some don't it seems. A Jira fits with me
Le 15/05/2019 à 14:29, Pawan Verma a écrit :
> Hello Devs,
>
> As we all know, Groovy is a powerful language with great built-in
> functions. Groovy Truth[1] is one of them, which is not used properly in
> our code base. We have used UtilValidate Class to validate arguments for
> Empty or NotEmpty, which can easily be done in groovy with built-in
> functionality.
>
> Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
>
> Groovy Built-in Code: if (locations) { ... }
>
> IMO, We should use this Groovy Truth feature instead of UtilValidate Class.
> Please let me know your thoughts on this. Thanks!
> [1] - http://groovy-lang.org/semantics.html#Groovy-Truth
>
> --
> Kind Regards
> Pawan Verma
> Technical Consultant
> *HotWax Systems*
>
Re: Code Improvement for Groovy
Posted by Pawan Verma <pa...@hotwaxsystems.com>.
Thanks Scott,
I'll keep that in my mind when changing this. Thanks!
--
Thanks & Regards
Pawan Verma
Technical Consultant
*HotWax Systems*
*Enterprise open source experts*
http://www.hotwaxsystems.com
On Thu, May 16, 2019 at 1:53 PM Jacques Le Roux <
jacques.le.roux@les7arts.com> wrote:
> Thanks Scott,
>
> Quite helpful!
>
> Jacques
>
> Le 16/05/2019 à 10:12, Scott Gray a écrit :
> > Hi Pawan
> >
> > Sounds good, just one point to be careful of:
> > maxRetry = 0
> > if (!maxRetry) {
> > // Not set, use a default
> > maxRetry = -1
> > }
> >
> > Because groovy evaluates zero to be false, it wouldn't be possible to set
> > maxRetry to zero. So it's best not to use groovy truth for null-checks
> on
> > numbers in some cases. I thought it was worth mentioning since there's a
> > higher risk of making this mistake when making changes in bulk.
> >
> > Regards
> > Scott
> >
> > On Thu, 16 May 2019 at 00:29, Pawan Verma <pawan.verma@hotwaxsystems.com
> >
> > wrote:
> >
> >> Hello Devs,
> >>
> >> As we all know, Groovy is a powerful language with great built-in
> >> functions. Groovy Truth[1] is one of them, which is not used properly in
> >> our code base. We have used UtilValidate Class to validate arguments for
> >> Empty or NotEmpty, which can easily be done in groovy with built-in
> >> functionality.
> >>
> >> Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
> >>
> >> Groovy Built-in Code: if (locations) { ... }
> >>
> >> IMO, We should use this Groovy Truth feature instead of UtilValidate
> Class.
> >> Please let me know your thoughts on this. Thanks!
> >> [1] - http://groovy-lang.org/semantics.html#Groovy-Truth
> >>
> >> --
> >> Kind Regards
> >> Pawan Verma
> >> Technical Consultant
> >> *HotWax Systems*
> >>
>
Re: Code Improvement for Groovy
Posted by Jacques Le Roux <ja...@les7arts.com>.
Thanks Scott,
Quite helpful!
Jacques
Le 16/05/2019 à 10:12, Scott Gray a écrit :
> Hi Pawan
>
> Sounds good, just one point to be careful of:
> maxRetry = 0
> if (!maxRetry) {
> // Not set, use a default
> maxRetry = -1
> }
>
> Because groovy evaluates zero to be false, it wouldn't be possible to set
> maxRetry to zero. So it's best not to use groovy truth for null-checks on
> numbers in some cases. I thought it was worth mentioning since there's a
> higher risk of making this mistake when making changes in bulk.
>
> Regards
> Scott
>
> On Thu, 16 May 2019 at 00:29, Pawan Verma <pa...@hotwaxsystems.com>
> wrote:
>
>> Hello Devs,
>>
>> As we all know, Groovy is a powerful language with great built-in
>> functions. Groovy Truth[1] is one of them, which is not used properly in
>> our code base. We have used UtilValidate Class to validate arguments for
>> Empty or NotEmpty, which can easily be done in groovy with built-in
>> functionality.
>>
>> Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
>>
>> Groovy Built-in Code: if (locations) { ... }
>>
>> IMO, We should use this Groovy Truth feature instead of UtilValidate Class.
>> Please let me know your thoughts on this. Thanks!
>> [1] - http://groovy-lang.org/semantics.html#Groovy-Truth
>>
>> --
>> Kind Regards
>> Pawan Verma
>> Technical Consultant
>> *HotWax Systems*
>>
Re: Code Improvement for Groovy
Posted by Scott Gray <sc...@hotwaxsystems.com>.
Hi Pawan
Sounds good, just one point to be careful of:
maxRetry = 0
if (!maxRetry) {
// Not set, use a default
maxRetry = -1
}
Because groovy evaluates zero to be false, it wouldn't be possible to set
maxRetry to zero. So it's best not to use groovy truth for null-checks on
numbers in some cases. I thought it was worth mentioning since there's a
higher risk of making this mistake when making changes in bulk.
Regards
Scott
On Thu, 16 May 2019 at 00:29, Pawan Verma <pa...@hotwaxsystems.com>
wrote:
> Hello Devs,
>
> As we all know, Groovy is a powerful language with great built-in
> functions. Groovy Truth[1] is one of them, which is not used properly in
> our code base. We have used UtilValidate Class to validate arguments for
> Empty or NotEmpty, which can easily be done in groovy with built-in
> functionality.
>
> Current Code: if (UtilValidate.isNotEmpty(locations)) { ... }
>
> Groovy Built-in Code: if (locations) { ... }
>
> IMO, We should use this Groovy Truth feature instead of UtilValidate Class.
> Please let me know your thoughts on this. Thanks!
> [1] - http://groovy-lang.org/semantics.html#Groovy-Truth
>
> --
> Kind Regards
> Pawan Verma
> Technical Consultant
> *HotWax Systems*
>