You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Michael Dürig <md...@apache.org> on 2012/08/14 15:47:49 UTC

Re: hasProperty vs getProperty


On 30.7.12 15:02, Alexander Klimetschek wrote:
> On 20.07.2012, at 14:58, Julian Reschke <ju...@gmx.de> wrote:
>
>> On 2012-07-20 14:41, Alexander Klimetschek wrote:
>>> On 20.07.2012, at 09:01, Julian Reschke wrote:
>>>
>>>> I agree with that, but that's how JCR works.
>>>
>>> Well, you have both options: if you use the has*() or (item|property|node)Exists() methods, and since PNFEx inherits from RepositoryEx, you can skip the try/catch for the application logic.
>>
>> That "works", but causes lots of unneeded work in the implementation;
>> which is exactly why I started this discussion.
>
> Yes, but this is one of the things that the infrastructure (i.e. JCR) should provide (without a penalty) instead of having to handle this again and again in your application or use ugly exception handling.
>
> But I agree that a get<Something>() returning null if it's not existing is also a very good idea, currently lacking from JCR.

An even better way to handle this is to return an Option<T>. Guava has 
something along these lines [1]. Unfortunately Guava's version of Option 
is not a monad which makes it not as useful as it could be.

Functional Java has a more complete implementation [2].

Michael

[1] 
http://code.google.com/p/guava-libraries/wiki/UsingAndAvoidingNullExplained
[2] 
http://functionaljava.googlecode.com/svn/artifacts/3.0/javadoc/fj/data/Option.html

>
> Cheers,
> Alex
>

Re: hasProperty vs getProperty

Posted by Michael Dürig <md...@apache.org>.

On 15.8.12 5:31, Julian Reschke wrote:
> On 2012-08-14 15:47, Michael Dürig wrote:
>> ...
>> An even better way to handle this is to return an Option<T>. Guava has
>> something along these lines [1]. Unfortunately Guava's version of Option
>> is not a monad which makes it not as useful as it could be.
>> ...
>
> It looks cool first, but I'm totally unconvinced that replacing null
> checks by "isPresent()" checks really makes things better.

That's the particular problem with the Guava implementation which 
doesn't provide map/flatMap methods. Having these you don't need 
isPresent() but rather lift your operation into the monad.

Michael

>
> Best regards, Julian

Re: hasProperty vs getProperty

Posted by Julian Reschke <ju...@gmx.de>.
On 2012-08-14 15:47, Michael Dürig wrote:
> ...
> An even better way to handle this is to return an Option<T>. Guava has
> something along these lines [1]. Unfortunately Guava's version of Option
> is not a monad which makes it not as useful as it could be.
> ...

It looks cool first, but I'm totally unconvinced that replacing null 
checks by "isPresent()" checks really makes things better.

Best regards, Julian