<div dir="ltr">I like the idea of using Optionals. But I think we would need to enhance all our APIs to use this (to be consistent). <div><br></div><div>Maybe you could come up with a small proposition of API changes? It might not work correctly (we can just mock them) but I would love to see some examples and "feel" the semantics.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 31, 2017 at 10:00 AM Tristan Tarrant <<a href="mailto:ttarrant@redhat.com">ttarrant@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was about to say the same: in the typical use case of returning an<br class="gmail_msg">
optional and using it immediately it would probably end up on the stack<br class="gmail_msg">
anyway...<br class="gmail_msg">
<br class="gmail_msg">
Tristan<br class="gmail_msg">
<br class="gmail_msg">
On 31/03/2017 09:57, Radim Vansa wrote:<br class="gmail_msg">
> I secretly hope that all these allocations would be inlined and<br class="gmail_msg">
> eliminated. If we find out that it really allocates the objects (from<br class="gmail_msg">
> JFR's allocation stats), it's a reason to rewrite that piece of code to<br class="gmail_msg">
> the dull optionless version.<br class="gmail_msg">
> TBH I am rather afraid that the JVM will allocate the consumer which<br class="gmail_msg">
> will need some captured variables. Maybe I trust C2 compiler too much,<br class="gmail_msg">
> believing that if the handler isn't too big, it will generate similar<br class="gmail_msg">
> instructions with nicer source code :-/<br class="gmail_msg">
><br class="gmail_msg">
> R.<br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
> On 03/30/2017 11:08 PM, Sanne Grinovero wrote:<br class="gmail_msg">
>> I'm for "at discretion" and "avoid if not really needed" : not cool to<br class="gmail_msg">
>> allocate objects for no reason.<br class="gmail_msg">
>><br class="gmail_msg">
>> On 30 Mar 2017 16:57, "Radim Vansa" <<a href="mailto:rvansa@redhat.com" class="gmail_msg" target="_blank">rvansa@redhat.com</a><br class="gmail_msg">
>> <mailto:<a href="mailto:rvansa@redhat.com" class="gmail_msg" target="_blank">rvansa@redhat.com</a>>> wrote:<br class="gmail_msg">
>><br class="gmail_msg">
>> Hi,<br class="gmail_msg">
>><br class="gmail_msg">
>> I was wondering what's the common attitude towards using Optional in<br class="gmail_msg">
>> APIs, and what naming pattern should we use. As an example, I dislike<br class="gmail_msg">
>> calling<br class="gmail_msg">
>><br class="gmail_msg">
>> if (entry.getMetadata() != null && entry.getMetadata().version()<br class="gmail_msg">
>> != null) {<br class="gmail_msg">
>> foo.use(entry.getMetadata().version())<br class="gmail_msg">
>> }<br class="gmail_msg">
>><br class="gmail_msg">
>> where I could just do<br class="gmail_msg">
>><br class="gmail_msg">
>> entry.metadata().flatMap(Metadata::optionalVersion).ifPresent(foo::use)<br class="gmail_msg">
>><br class="gmail_msg">
>> Here I have proposed metadata() method returning Optional<Metadata><br class="gmail_msg">
>> (regular getter method is called getMetadata()) and annoying<br class="gmail_msg">
>> optionalVersion() as version() is the regular getter.<br class="gmail_msg">
>><br class="gmail_msg">
>> Shall we adopt some common stance (use/don't use/use at developer's<br class="gmail_msg">
>> discretion) and naming conventions? Is it acceptable to start adding<br class="gmail_msg">
>><br class="gmail_msg">
>> default Optional<Foo> foo() { Optional.ofNullable(getFoo()); }<br class="gmail_msg">
>><br class="gmail_msg">
>> whenever we feel the urge to chain Optionals?<br class="gmail_msg">
>><br class="gmail_msg">
>> Radim<br class="gmail_msg">
>><br class="gmail_msg">
>> --<br class="gmail_msg">
>> Radim Vansa <<a href="mailto:rvansa@redhat.com" class="gmail_msg" target="_blank">rvansa@redhat.com</a> <mailto:<a href="mailto:rvansa@redhat.com" class="gmail_msg" target="_blank">rvansa@redhat.com</a>>><br class="gmail_msg">
>> JBoss Performance Team<br class="gmail_msg">
>><br class="gmail_msg">
>> _______________________________________________<br class="gmail_msg">
>> infinispan-dev mailing list<br class="gmail_msg">
>> <a href="mailto:infinispan-dev@lists.jboss.org" class="gmail_msg" target="_blank">infinispan-dev@lists.jboss.org</a> <mailto:<a href="mailto:infinispan-dev@lists.jboss.org" class="gmail_msg" target="_blank">infinispan-dev@lists.jboss.org</a>><br class="gmail_msg">
>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br class="gmail_msg">
>> <<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a>><br class="gmail_msg">
>><br class="gmail_msg">
>><br class="gmail_msg">
>><br class="gmail_msg">
>> _______________________________________________<br class="gmail_msg">
>> infinispan-dev mailing list<br class="gmail_msg">
>> <a href="mailto:infinispan-dev@lists.jboss.org" class="gmail_msg" target="_blank">infinispan-dev@lists.jboss.org</a><br class="gmail_msg">
>> <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Tristan Tarrant<br class="gmail_msg">
Infinispan Lead<br class="gmail_msg">
JBoss, a division of Red Hat<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
infinispan-dev mailing list<br class="gmail_msg">
<a href="mailto:infinispan-dev@lists.jboss.org" class="gmail_msg" target="_blank">infinispan-dev@lists.jboss.org</a><br class="gmail_msg">
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br class="gmail_msg">
</blockquote></div>