[Neo4j] TraversalDescription building hickup

2010-07-27 Thread Peter Neubauer
Hi all,
I just stumbled over the immutable TraversalDescription API
(http://components.neo4j.org/neo4j-kernel/apidocs/index.html), which
will not modify the object if you do

TraversalDescription td = new TraversalDescriptionImpl();
td.depthFirst();

Instead, one needs to reassign td, like

TraversalDescription td = new TraversalDescriptionImpl();
td = td.depthFirst();

However,
TraversalDescription td = new TraversalDescriptionImpl().depthFirst();

will give you the expected td.

IMHO this is unexpected behaviour and hard to get if you just follow
the common fluent API and presume a Builder-pattern. Especially since
no errors are thrown and you just end up with strange results and
unreachable code i e.g. a custom PruneEvaluator etc. True, the API
says it is immutable, but still I think this is hard.

WDYT?

Should we think of changing this to a proper builder.modify().modify
etc and finally builder.build() wich gives you the final, immutable
instance of TraversalDescription and is clearly understandable by
clients?

Cheers,

/peter neubauer

COO and Sales, Neo Technology

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

http://www.neo4j.org               - Your high performance graph database.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] TraversalDescription building hickup

2010-07-27 Thread Mattias Persson
2010/7/27 Peter Neubauer peter.neuba...@neotechnology.com

 Hi all,
 I just stumbled over the immutable TraversalDescription API
 (http://components.neo4j.org/neo4j-kernel/apidocs/index.html), which
 will not modify the object if you do

 TraversalDescription td = new TraversalDescriptionImpl();
 td.depthFirst();

 Instead, one needs to reassign td, like

 TraversalDescription td = new TraversalDescriptionImpl();
 td = td.depthFirst();

 However,
 TraversalDescription td = new TraversalDescriptionImpl().depthFirst();

 will give you the expected td.

 IMHO this is unexpected behaviour and hard to get if you just follow
 the common fluent API and presume a Builder-pattern. Especially since
 no errors are thrown and you just end up with strange results and
 unreachable code i e.g. a custom PruneEvaluator etc. True, the API
 says it is immutable, but still I think this is hard.

 WDYT?

 Should we think of changing this to a proper builder.modify().modify
 etc and finally builder.build() wich gives you the final, immutable
 instance of TraversalDescription and is clearly understandable by
 clients?


I still think the current approach is more useful (although it'd be nice
with more input on this). One reason I think it's better is that you can
half-bake descriptions as private static final or similar and then complete
the descriptions in several different places in your code. You can even pass
in descriptions in methods and what not, without any risc of them being
modified. I think javadoc should better explain this and it should be
expected that developers read javadoc, right?



 Cheers,

 /peter neubauer

 COO and Sales, Neo Technology

 GTalk:  neubauer.peter
 Skype   peter.neubauer
 Phone   +46 704 106975
 LinkedIn   http://www.linkedin.com/in/neubauer
 Twitter  http://twitter.com/peterneubauer

 http://www.neo4j.org   - Your high performance graph database.
 http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user




-- 
Mattias Persson, [matt...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] TraversalDescription building hickup

2010-07-27 Thread Paul A. Jackson
I may have missed your point.  But, FWIW, this model reflects what I would 
expect from an immutable object.
For example:
String s = Test;
s.replace('T', 't'); // s still contains Test

BigInteger and Date are the same way.

-Paul



-Original Message-
From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On 
Behalf Of Mattias Persson
Sent: Tuesday, July 27, 2010 2:41 PM
To: Neo4j user discussions
Subject: Re: [Neo4j] TraversalDescription building hickup

2010/7/27 Peter Neubauer peter.neuba...@neotechnology.com

 Hi all,
 I just stumbled over the immutable TraversalDescription API
 (http://components.neo4j.org/neo4j-kernel/apidocs/index.html), which
 will not modify the object if you do

 TraversalDescription td = new TraversalDescriptionImpl();
 td.depthFirst();

 Instead, one needs to reassign td, like

 TraversalDescription td = new TraversalDescriptionImpl();
 td = td.depthFirst();

 However,
 TraversalDescription td = new TraversalDescriptionImpl().depthFirst();

 will give you the expected td.

 IMHO this is unexpected behaviour and hard to get if you just follow
 the common fluent API and presume a Builder-pattern. Especially since
 no errors are thrown and you just end up with strange results and
 unreachable code i e.g. a custom PruneEvaluator etc. True, the API
 says it is immutable, but still I think this is hard.

 WDYT?

 Should we think of changing this to a proper builder.modify().modify
 etc and finally builder.build() wich gives you the final, immutable
 instance of TraversalDescription and is clearly understandable by
 clients?


I still think the current approach is more useful (although it'd be nice
with more input on this). One reason I think it's better is that you can
half-bake descriptions as private static final or similar and then complete
the descriptions in several different places in your code. You can even pass
in descriptions in methods and what not, without any risc of them being
modified. I think javadoc should better explain this and it should be
expected that developers read javadoc, right?



 Cheers,

 /peter neubauer

 COO and Sales, Neo Technology

 GTalk:  neubauer.peter
 Skype   peter.neubauer
 Phone   +46 704 106975
 LinkedIn   http://www.linkedin.com/in/neubauer
 Twitter  http://twitter.com/peterneubauer

 http://www.neo4j.org   - Your high performance graph database.
 http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user




-- 
Mattias Persson, [matt...@neotechnology.com]
Hacker, Neo Technology
www.neotechnology.com
___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user


Re: [Neo4j] TraversalDescription building hickup

2010-07-27 Thread Craig Taverner
I think the key point of Peters request is to separate the 'builder' from
the 'traverser'. Mattias argument appears to state that if the builder and
traverser are the same class (series of immutable instances of the same
class), you have more flexibility in refactoring, because you don't have to
remember to convert to the traverser as the last step (Peter called build()
as the last step of a builder creating a 'really immutable' traverser).

The example of String.replace is similar to Mattias description, one
immutable object creating another instance of the same class. However, I
personally think Peter has a point. Keeping the builder and traverser as two
separate objects might force the coder to make a clear decision about when
the traverser should no longer be modified. Once the build() method is
called, we are done. Before that point the developer still has complete
flexibility to modify the traversal rules multiple times in as many steps
and places in the code they want, but once they call build(), the returned
traverser cannot be modified at all.

Despite my argument above favouring Peters approach, I actually do not have
a strong opinion on this, and think both ways are good. I confess that had I
coded this myself there is a good way I would have done it with one class
like Mattias describes.

(and I just realized another thing, we normally access traversers in
for(Iterable) loops that call iterator(), which itself returns a 'really
immutable' object, so perhaps adding another in the chain is overkill :-)

On Tue, Jul 27, 2010 at 9:00 PM, Paul A. Jackson paul.jack...@pb.comwrote:

 I may have missed your point.  But, FWIW, this model reflects what I would
 expect from an immutable object.
 For example:
 String s = Test;
 s.replace('T', 't'); // s still contains Test

 BigInteger and Date are the same way.

 -Paul



 -Original Message-
 From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org]
 On Behalf Of Mattias Persson
 Sent: Tuesday, July 27, 2010 2:41 PM
 To: Neo4j user discussions
 Subject: Re: [Neo4j] TraversalDescription building hickup

 2010/7/27 Peter Neubauer peter.neuba...@neotechnology.com

  Hi all,
  I just stumbled over the immutable TraversalDescription API
  (http://components.neo4j.org/neo4j-kernel/apidocs/index.html), which
  will not modify the object if you do
 
  TraversalDescription td = new TraversalDescriptionImpl();
  td.depthFirst();
 
  Instead, one needs to reassign td, like
 
  TraversalDescription td = new TraversalDescriptionImpl();
  td = td.depthFirst();
 
  However,
  TraversalDescription td = new TraversalDescriptionImpl().depthFirst();
 
  will give you the expected td.
 
  IMHO this is unexpected behaviour and hard to get if you just follow
  the common fluent API and presume a Builder-pattern. Especially since
  no errors are thrown and you just end up with strange results and
  unreachable code i e.g. a custom PruneEvaluator etc. True, the API
  says it is immutable, but still I think this is hard.
 
  WDYT?
 
  Should we think of changing this to a proper builder.modify().modify
  etc and finally builder.build() wich gives you the final, immutable
  instance of TraversalDescription and is clearly understandable by
  clients?
 

 I still think the current approach is more useful (although it'd be nice
 with more input on this). One reason I think it's better is that you can
 half-bake descriptions as private static final or similar and then complete
 the descriptions in several different places in your code. You can even
 pass
 in descriptions in methods and what not, without any risc of them being
 modified. I think javadoc should better explain this and it should be
 expected that developers read javadoc, right?


 
  Cheers,
 
  /peter neubauer
 
  COO and Sales, Neo Technology
 
  GTalk:  neubauer.peter
  Skype   peter.neubauer
  Phone   +46 704 106975
  LinkedIn   http://www.linkedin.com/in/neubauer
  Twitter  http://twitter.com/peterneubauer
 
  http://www.neo4j.org   - Your high performance graph
 database.
  http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
  ___
  Neo4j mailing list
  User@lists.neo4j.org
  https://lists.neo4j.org/mailman/listinfo/user
 



 --
 Mattias Persson, [matt...@neotechnology.com]
 Hacker, Neo Technology
 www.neotechnology.com
 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

 ___
 Neo4j mailing list
 User@lists.neo4j.org
 https://lists.neo4j.org/mailman/listinfo/user

___
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user