You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Diego Ceccarelli (BLOOMBERG/ LONDON)" <dc...@bloomberg.net> on 2019/04/10 17:20:35 UTC

Using util.Optional instead of a raw null?

Hi *, 
I have a general question about using Optional instead of a raw null:
I have noticed that some functions in Solr are dealing with input parameters that might be null, these parameters might be wrapped into Optional - to avoid forgetting that they might be nulls and also to make clear that they are.. optional. 

For example in marshalOrUnmarshalSortValue https://github.com/apache/lucene-solr/blob/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/ShardResultTransformerUtils.java#L37

both originalSortValue and schemaField are optional, and we might declare them Optional. 
any opinion? 

Cheers,
Diego

Re: Using util.Optional instead of a raw null?

Posted by Gus Heck <gu...@gmail.com>.
I'm not so keen on using optional for parameters (-0). It's really for
return values. I tend to agree with this SO answer:
https://stackoverflow.com/a/31923105 YMMV

On Fri, Apr 19, 2019 at 12:43 AM Tomás Fernández Löbbe <
tomasflobbe@gmail.com> wrote:

> In general, I'm +1. I think we may want to be careful in the cases where
> too many objects would be created, like when iterating docs/values, etc.
> That specific case you link to would be a good candidate in my mind.
>
> On Wed, Apr 10, 2019 at 10:20 AM Diego Ceccarelli (BLOOMBERG/ LONDON) <
> dceccarelli4@bloomberg.net> wrote:
>
>> Hi *,
>> I have a general question about using Optional instead of a raw null:
>> I have noticed that some functions in Solr are dealing with input
>> parameters that might be null, these parameters might be wrapped into
>> Optional - to avoid forgetting that they might be nulls and also to make
>> clear that they are.. optional.
>>
>> For example in marshalOrUnmarshalSortValue
>> https://github.com/apache/lucene-solr/blob/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/ShardResultTransformerUtils.java#L37
>>
>> both originalSortValue and schemaField are optional, and we might declare
>> them Optional.
>> any opinion?
>>
>> Cheers,
>> Diego
>>
>

-- 
http://www.the111shift.com

Re: Using util.Optional instead of a raw null?

Posted by Tomás Fernández Löbbe <to...@gmail.com>.
In general, I'm +1. I think we may want to be careful in the cases where
too many objects would be created, like when iterating docs/values, etc.
That specific case you link to would be a good candidate in my mind.

On Wed, Apr 10, 2019 at 10:20 AM Diego Ceccarelli (BLOOMBERG/ LONDON) <
dceccarelli4@bloomberg.net> wrote:

> Hi *,
> I have a general question about using Optional instead of a raw null:
> I have noticed that some functions in Solr are dealing with input
> parameters that might be null, these parameters might be wrapped into
> Optional - to avoid forgetting that they might be nulls and also to make
> clear that they are.. optional.
>
> For example in marshalOrUnmarshalSortValue
> https://github.com/apache/lucene-solr/blob/1d85cd783863f75cea133fb9c452302214165a4d/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/ShardResultTransformerUtils.java#L37
>
> both originalSortValue and schemaField are optional, and we might declare
> them Optional.
> any opinion?
>
> Cheers,
> Diego
>