[ 
https://issues.apache.org/jira/browse/HBASE-19682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16317349#comment-16317349
 ] 

Appy edited comment on HBASE-19682 at 1/9/18 12:29 AM:
-------------------------------------------------------

The test failures may indeed be not related since no common failures between 
last two runs. --Thanks for the patch [~belugabehr]. Let me push it to master.--

On second thought, i don't think it's good idea to return a 
Collections.emptyList(), which is an immutable object, from a function with 
return type List<T>.

Image seeing a fn:
List<Foo> getBaseFoos() {...}
and doing 
List<Foo> myFoos = getBaseFoos();
myFoos.add(myfoo1);
myFoos.add(myfoo2);
And getting runtime error that list is immutable.
Such an uncertainty in return type makes code readability very hard.

I think a simple rule to make things easier here is:
- when returning List<> type is imperative, one should return {{new 
ArrayList<>(0)}} for empty cases.
- when return type doesn't necessarily has to be List<>, it should be changed 
to Iterable<> as return type and then {{return Collections.emptyList()}} can be 
used.

In this case, can you please change the return types of relevant functions to 
Iterable<>.
When the returned valued is used as stream, do as [this 
stackoverflow|https://stackoverflow.com/questions/23114015/why-does-iterablet-not-provide-stream-and-parallelstream-methods?rq=1]
 suggests. I agree that readability is less when using StreamSupport, but in 
tradeoff of uncertainty and readability, i think there's a clear choice.
Thanks.



was (Author: appy):
The test failures may indeed be not related since no common failures between 
last two runs. --Thanks for the patch [~belugabehr]. Let me push it to master.--

On second thought, i don't think it's good idea to return a 
Collections.emptyList(), which is an immutable object, from a function with 
return type List<T>.

Image seeing a fn:
List<Foo> getBaseFoos() {...}
and doing 
List<Foo> myFoos = getBaseFoos();
myFoos.add(myfoo1);
myFoos.add(myfoo2);
And getting runtime error that list is immutable.
Such an uncertainty in return type makes code readability very hard.

I think a simple rule to make things easier here is:
- when returning List<> type is imperative, one should return {{new 
ArrayList<>(0)}} for empty cases.
- when return type doesn't necessarily has to be List<>, it should be changed 
to Iterable<> as return type and then {{return Collections.emptyList()}} can be 
used.

In this case, can you please change the return types of relevant functions to 
Iterable<>.
When the returned valued is used as stream, do as [this 
stackoverflow|https://stackoverflow.com/questions/23114015/why-does-iterablet-not-provide-stream-and-parallelstream-methods?rq=1]
 suggests.
Thanks.


> Use Collections.emptyList() For Empty List Values
> -------------------------------------------------
>
>                 Key: HBASE-19682
>                 URL: https://issues.apache.org/jira/browse/HBASE-19682
>             Project: HBase
>          Issue Type: Improvement
>          Components: hbase
>    Affects Versions: 3.0.0
>            Reporter: BELUGA BEHR
>            Assignee: BELUGA BEHR
>            Priority: Minor
>         Attachments: HBASE-19682.1.patch, HBASE-19682.2.patch, 
> HBASE-19682.3.1.patch
>
>
> Use {{Collection.emptyList()}} for returning an empty list instead of 
> {{return new ArrayList<> ()}}.  The default constructor creates a buffer of 
> size 10 for _ArrayList_ therefore, returning this static value saves on some 
> memory and GC pressure and saves time not having to allocate a new internally 
> buffer for each instantiation.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to