groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: [CONTRIBUTION]groovy-option-support
Date Tue, 16 Aug 2016 14:20:21 GMT


On 12.08.2016 17:39, daniel_sun wrote:
> Hi all,
>
>         The option
> pattern(http://www.codecommit.com/blog/scala/the-option-pattern) is very
> useful to improve the robustness of program by avoiding NPE. Scala and Rust
> have build in the
> pattern(http://www.tutorialspoint.com/scala/scala_options.htm), but Groovy
> currently is lack of it.
>..
>          In order to introduce the option pattern into Groovy, I am willing
> to contribute my project
> "groovy-option-support"(https://github.com/danielsun1106/groovy-option-support)
> to Groovy, which is also licensed under APL2. If the contribution is
> accepted, please review the code and I'll try to improve it as your
> suggestions.

thanks for the offer. Now the mean question ;) Why should we base this 
on a scala style Optional instead of the Java8 Option?

Option.$new would be Optional.ofNullable, instead of checking for None 
or Some you would check on Optional#isPresent().

Adding something like your $switch can be done using... well, I guess I 
would be using some combination of map and orElse or maybe a simple 
if-else... depends highly on the code.

So I wonder now what the difference would be between your idea and Java 
Optional extended by some DGM methods... for example for groovy truth or 
the iterator.

And the main differences I spot are:

* Option available under for pre Java8 as well
* Optional has better integration in the existing libraries

Considering that we now require Java7 as minimum and that we want to 
change to 8 as soon as seems to be feasible, I tend not to count the 
first point as negative for Optional. Especially considering that Groovy 
is really anything but a "avoid null"-language.

What do you think of adding some DGM methods for Optional instead and 
let us use that instead of integrating your library?

bye Jochen


Mime
View raw message